trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
361 stars 18 forks source link

Gradient patterns not working in RStudio/RMarkdown #51

Closed Mfoley196 closed 3 years ago

Mfoley196 commented 3 years ago

I'm using R 4.1.0 and RStudio 1.4.1717.

Gradient patterns aren't working when I try to use them in an RMarkdown file - only the ggplot fill is shown on the geoms.

See attached zip with an Rmd file and the html output of one of the gradient examples used in the documentation. In this example, the gradients do not display. gradient-test.zip

trevorld commented 3 years ago

I'm guessing either these two options will work to "fix" it

1) Add options(ggpattern_use_R4.1_gradients = FALSE)

or

2) Make sure your png device is set to the "cairo" flavor (and not the "Xlib" nor "quartz" flavors).

My guess is that {gridpattern} sees you are using a png device and also has R >= 4.1.0 installed so it makes an educated guess that your graphic device has R 4.1 gradient support but maybe on your platform you png device defaults to the "Xlib" or "quartz" flavors which lack such support?

Mfoley196 commented 3 years ago

The first option worked to fix the issue! Thanks for your help - I had an inkling my issue was related to me updating R, but had no idea what the specific problem was. :)

trevorld commented 3 years ago

I'd appreciate it if someone impacted by this can confirm:

1) Which R graphics device being used 2) Which R version is being used 3) OS

And then see if this "bug" reproduces if using that graphics device outside RStudio/RMarkdown.

gridpattern behaviour is supposed to be conservative and only assume R 4.1.0 gradient support only for graphic devices it knows supports that feature so this shouldn't theoretically happen.

One hypothetical possibility is that RStudio/RMarkdown is trying to be clever and initially renders with one graphics device that supports R 4.1.0 gradient support and then use dev.copy() to render to another graphics device that doesn't support it?