Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap_plot() overrides ggsave() "bg" argument #292

Closed
picasa opened this issue Feb 11, 2022 · 1 comment
Closed

wrap_plot() overrides ggsave() "bg" argument #292

picasa opened this issue Feb 11, 2022 · 1 comment

Comments

@picasa
Copy link

picasa commented Feb 11, 2022

Hi, not sure if i should post in patchwork or ggsave repository, but i noticed that the bg argument from ggsave was not functioning as expected with a plot constructed by patchwork: in the below example, the file "test_ok.jpg" has the expected background color, while "test_nok.jpg" has default background. Is it a normal behaviour for patchwork plots ?

Thanks !

library(ggplot2)
library(patchwork)

p1 <- ggplot(data = cars) + geom_point(aes(x=speed, y=dist)) + theme_void()

p2 <- wrap_plots(p1)

ggsave(p1, file = "test_ok.jpg", width = 1, height = 1, bg = "#124270")
ggsave(p2, file = "test_nok.jpg", width = 1, height = 1, bg = "#124270")

Created on 2022-02-11 by the reprex package (v2.0.1)

@thomasp85
Copy link
Owner

This is because a patchwork has its own distinct theme and background as well (which defaults to "white"). You can override this using either plot_annotation(theme = ...) or by applying a theme with the & operator which will set the theme of all included plots as well as the full patchwork

p3 <- p2 & theme_void()

ggsave(p3, file = "test_hopefully_ok.jpg", width = 1, height = 1, bg = "#124270")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants