我想更改geoms
中所有ggplot2
的默认颜色和填充。我遇到了this post和this post,这有助于我开始更改默认值。
但是,当我尝试使用update_geom_defaults
或update_stat_defaults
更改直方图的默认值时,出现错误:
错误:找不到名为“直方图”的
geom
是否可以使用geom_histogram
为update_*_defaults
更新颜色和填充?
代码:
library(tidyverse)
update_geom_defaults("histogram", list(fill = "black", colour = "black"))
update_stat_defaults("histogram", list(fill = "black", colour = "black"))
#works in ggplot call
ggplot(mtcars)+
geom_histogram(aes(x=mpg), bins = 5, fill = "black")
#works for other geom_*
update_geom_defaults("point", list(fill = "green", colour = "green"))
ggplot(mtcars)+
geom_point(aes(x=mpg,y=cyl))
#additional arguments that do not work with either update function
neither <- c("freqpoly", "histogram", "jitter","sf_label","sf_text")
为ggplot2
使用版本R 3.6和3.2.0