Reputation: 193
I am having an issue where a few months ago, the behavior of ggsave()
seemed to change, defaulting to a transparent background instead of a white background. For instance this code:
box_plot <-ggplot(vaccine_data_summary, aes(y = vaccine_uptake, x = region)) +
geom_boxplot(outlier.shape = NA)
ggsave("box_plot.png", plot = box_plot, width = 1200, height = 675, units = "px", scale = 2)
Results in a transparent background. To fix this I have been adding the argument for background.
ggsave("box_plot.png", plot = box_plot, width = 1200, height = 675, units = "px", bg = "white", scale = 2)
However, I would prefer to set the default to white again so I wouldn't have to update all of my old code.
Upvotes: 14
Views: 9969
Reputation: 388817
You can override the ggsave
function.
ggsave <- function(..., bg = 'white') ggplot2::ggsave(..., bg = bg)
Now when you call ggsave
function it would use this function with default bg
value as 'white'
.
Upvotes: 16