This question already has an answer here:
这个问题在这里已有答案:
- How to change default aesthetics in ggplot? 2 answers
如何在ggplot中更改默认美学? 2个答案
I'd like to define a theme for ggplot2 so that the default colour of geom_bar() is not black.
我想为ggplot2定义一个主题,以便geom_bar()的默认颜色不是黑色。
How can I do this?
我怎样才能做到这一点?
2 个解决方案
#1
7
you can't do it in a theme (sadly).
你不能在主题中做到这一点(遗憾的是)。
You want to change the default settings of a geom,
您想要更改geom的默认设置,
update_geom_defaults("bar", list(fill = "red"))
and you can also change a default scale, e.g.
您还可以更改默认比例,例如
scale_colour_continuous <- function(...)
scale_colour_gradient(low = "blue", high = "red", na.value="grey50", ...)
#2
1
Theme controls apperance of non-data elements, so you need to work with scale
functions. Try scale_fill_brewer
, e.g.:
主题控制非数据元素的外观,因此您需要使用缩放功能。尝试scale_fill_brewer,例如:
scale_fill_brewer(palette = "Set1")
For details on this function see here.
有关此功能的详细信息,请参见此处
#1
7
you can't do it in a theme (sadly).
你不能在主题中做到这一点(遗憾的是)。
You want to change the default settings of a geom,
您想要更改geom的默认设置,
update_geom_defaults("bar", list(fill = "red"))
and you can also change a default scale, e.g.
您还可以更改默认比例,例如
scale_colour_continuous <- function(...)
scale_colour_gradient(low = "blue", high = "red", na.value="grey50", ...)
#2
1
Theme controls apperance of non-data elements, so you need to work with scale
functions. Try scale_fill_brewer
, e.g.:
主题控制非数据元素的外观,因此您需要使用缩放功能。尝试scale_fill_brewer,例如:
scale_fill_brewer(palette = "Set1")
For details on this function see here.
有关此功能的详细信息,请参见此处