【问题标题】:Changing default ggsave background color更改默认 ggsave 背景颜色
【发布时间】:2021-11-24 15:25:26
【问题描述】:

我遇到了一个问题,几个月前,ggsave() 的行为似乎发生了变化,默认为透明背景而不是白色背景。例如这段代码:

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) 

产生透明背景。为了解决这个问题,我一直在添加背景参数。

ggsave("box_plot.png", plot = box_plot,  width = 1200, height = 675, units = "px", bg = "white", scale  = 2) 

但是,我希望将默认设置再次设置为白色,这样我就不必更新所有旧代码。

【问题讨论】:

  • 你的ggplot2版本是什么?在 ggsave() 中修复了 3.5.4
  • 是3.3.5版。

标签: r ggplot2


【解决方案1】:

您可以覆盖ggsave 函数。

ggsave <- function(..., bg = 'white') ggplot2::ggsave(..., bg = bg)

现在,当您调用 ggsave 函数时,它将使用此函数,默认 bg 值为 'white'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2018-01-05
    • 2014-10-04
    • 2016-01-15
    • 1970-01-01
    相关资源
    最近更新 更多