ggpattern | ggplot geoms with pattern fills | Data Visualization library
kandi X-RAY | ggpattern Summary
kandi X-RAY | ggpattern Summary
ggplot geoms with pattern fills
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ggpattern
ggpattern Key Features
ggpattern Examples and Code Snippets
Community Discussions
Trending Discussions on ggpattern
QUESTION
The code I have for the following plot is:
...ANSWER
Answered 2022-Mar-25 at 06:29One option would be to map your group column on the alpha
aes which will add a second legend to your plot. Afterwards fix the alpha
value at one, remove the fill legend and override the fill color of the alpha legend:
QUESTION
I am trying to install the ggpattern package from GitHub (https://www.rdocumentation.org/packages/ggpattern/versions/0.2.0)
I've reinstalled R, followed the all steps according to the site, also tried
remotes::install_github("coolbutuseless/ggpattern", force = TRUE)
But I still get:
...ANSWER
Answered 2022-Jan-30 at 07:32You need to check if you have a personal access token set in your environment. For example, when I have a Git project, I set a personal access token. However, I set this in the project environment, so that it isn't any issues outside of that environment.
To see if there is one assigned:
QUESTION
I made some maps with spatial features from the sf package and used ggpattern to create a striped fill. This worked well for certain polygons, but not for those with holes in it (islands in a lake feature class).
Recently the ggpattern package has been updated to work with polygons with holes (for which I am grateful!), and it no longer gives errors for these features but now the pattern fill is wrong for all features (with and without holes), since it no longer follows the polygon borders but instead fills a rectangle around the polygons.
Here's an example using the rnaturalearth package to show what I mean.
...ANSWER
Answered 2022-Jan-14 at 10:42I got the same issue. If you go on Github it's bug already reported. However, the solution proposed doesn't work for me. So I propose you an alternative solution.
QUESTION
I would like to change the color of a shared color to a different color, let's say red. So far, I am plotting the German federal state Bavaria and touching Austrian states. I get the data from https://gadm.org/download_country.html -
Germany Level 2 - https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_DEU_2_sf.rds
Germany Level 1 - https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_DEU_1_sf.rds
Austria Level 2 - https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_AUT_2_sf.rds
Austria Level 1 - https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_AUT_1_sf.rds
...ANSWER
Answered 2021-Dec-14 at 13:46Drawing a shared border is kind of tricky in context of {sf}
> 1.0, as it uses the s2 dependency for spherical operations, and the s2 library introduced a new concept of semi-closed polygons (which was not there in the GEOS years).
See https://r-spatial.github.io/s2/reference/s2_options.html#model for more information.
Anyhow, consider this piece of code, built on {giscoR}
package to access EU NUTS regions, and sf::st_intersection()
to find the shared border. Note the use of model = "closed"
(i.e. all polygons contain their entire boundaries) which may not be immediately obvious, and is necessary for the code to work as intended.
QUESTION
Similar questions have been asked before in other forms. Some can be found here and here. However, I cant seem to adapt them when using a facet wrap displaying multiple density plots.
I tried adapting the other examples, but failed... I also tried using the ggpattern
package, but when there is a large amount of data, it takes several minutes on my machine to create a plot.
I am trying to create a gradient under the density curve... but with the gradient pointing down. Something like in the example image below:
Some example data to work with:
...ANSWER
Answered 2021-Dec-05 at 15:43You can use teunbrand's function, but you will need to apply it to each facet. Here simply looping over it with lapply
QUESTION
ANSWER
Answered 2021-Sep-22 at 14:50You just need to add pattern in geom_bar_pattern
pattern = rep(c('none','stripe'),6),
Pattern is the key part of geom_bar_pattern. You can choose from 'stripe' (default), 'crosshatch', 'point', 'circle', 'none'. And the length of pattern needs to be either one or the same as the data.
QUESTION
I'm not able to customise the legends I have with ggplot/ggpattern.
- The "SPEED" legend should not display any pattern (just the 3 colors)
- The "TYPE" legend should have custom texts instead of 0 and 1
thanks!
code:
...ANSWER
Answered 2021-Jul-02 at 23:01You can change legend key labels within the relevant scale_*_*()
function by passing a vector with the labels to the labels
argument.
To change the legend without changing the plot you most often need override.aes
in guide_legend()
. Here is an example using it within scale_pattern_manual()
and overriding the pattern
aesthetic by setting it to "none".
QUESTION
I used grid.draw() function of ggnewscale package to get the plot
But it seems the way of download is not the same to ggplot2 type.
I used pdf() to save my plot result in shinyapp.
But when I click the download button the plot result is not picture type or not pdf
It confused me and I viewed several methods(here) but it doesn't work
I also get some advice Here
Here is my reproducible code and data:
...ANSWER
Answered 2021-Apr-15 at 16:18Here is my solution .I found a fantastic package that gives me inspiration.
The ggplotify package is created by Guangchuang Yu (School of Basic Medical Sciences, Southern Medical University China)
There is a as.ggplot()
function. A amazing function.
More secrets about ggplotify
can be found here
In my code, I just add as.ggplot
in p1()
,or p2()
.Just to view my answer code below:
QUESTION
I use the code below.
The order of the legends on the right is city
, split
. How can I reverse the order to split
, city
? I tried to use order in guides()
, but that does not work. How to solve this?
ANSWER
Answered 2021-Mar-14 at 22:59My slight change to guides()
results in split
being displayed above city
in the legend. Please note the difference in order
. There is no order = 0
.
QUESTION
I found the following example that explains how to add patterns to the geom_tile plot but I cannot get my plot to show by following the steps. Attached is a few rows of the data:
DATA:
...ANSWER
Answered 2021-Mar-04 at 17:22Here I've created a variable with the pattern so that we can use scale_pattern_identity
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ggpattern
Take an existing plot which contains a geom with a fillable area e.g geom_col().
Use the {ggpattern} version of the geom e.g. ggpattern::geom_col_pattern() instead of ggplot2::geom_col()
Set the aesthetic pattern to your choice of pattern e.g pattern = 'stripe', and set other options using pattern_* aesthetics
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page