Skip to content

Fix saving plots with no background - #4244

Merged
karawoo merged 3 commits into
tidyverse:masterfrom
karawoo:background-fix
Oct 28, 2020
Merged

karawoo merged 3 commits into
tidyverse:masterfrom
karawoo:background-fix

Conversation

@karawoo

@karawoo karawoo commented Oct 20, 2020

Copy link
Copy Markdown
Member

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.

Comment thread R/save.r Outdated
}
if (is_null(bg)) {
bg <- calc_element("plot.background", plot_theme(plot))$fill
if (is_null(bg)) {

Copy link
Copy Markdown
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
Copy Markdown
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