Skip to content

Conversation

karawoo
Copy link
Member

@karawoo karawoo commented Oct 20, 2020

Fixes #4212. When the plot.background itself is NULL, ggsave() will set the device bg to "transparent". This seems to work for devices that support transparent backgrounds. JPEGs and PDFs will have a white background, which seems ok.

R/save.r Outdated
@@ -88,6 +88,9 @@ ggsave <- function(filename, plot = last_plot(),
}
if (is_null(bg)) {
bg <- calc_element("plot.background", plot_theme(plot))$fill
if (is_null(bg)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just write:

bg <- calc_element("plot.background", plot_theme(plot))$fill %||% "transparent"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh of course, thanks, will update

@karawoo karawoo merged commit a132727 into tidyverse:master Oct 28, 2020
sthagen added a commit to sthagen/tidyverse-ggplot2 that referenced this pull request Nov 7, 2020
Fix saving plots with no background (tidyverse#4244)
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

Successfully merging this pull request may close these issues.

ggsave to svg fails for certain themes
2 participants