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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With