Skip to content

Fix saving plots with no background #4244

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

Merged
merged 3 commits into from
Oct 28, 2020
Merged

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