设置geom和scale ggplot2的默认值 [英] Setting Defaults for geoms and scales ggplot2
问题描述
+ opt()...
行的需求。但是,我想知道是否有方法来定义geoms和scale颜色的默认值。我不想为每个绘图编写 ... + scale_fill_manual()
,我希望能够设置并忘记它。同样,我希望能够设置geom选项,所以我不必重新输入(或忘记重新输入)诸如 geom_text(...,size = 3,color =white )
更新:
对于比例尺来说,是一种方法:
set_default_scale(color,discrete,gray)
但是这个函数似乎并不存在于ggplot2的最新版本中。
现在还有另一种方法。例如:
scale_colour_discrete< - function(...)scale_colour_brewer(...)您可以基本覆盖任何美学比例。 ,... palette =Set2)
scale_fill_discrete< - function(...)scale_fill_brewer(...,palette =Set2)
现在,您的美学将会根据该行为进行着色或填充。'
按照 https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/w0Tl0T_U9dI
关于geoms的默认值,您可以使用 update_geom_defaults
,例如:
update_geom_defaults(line,list(size = 2))
Theming for ggplot2 makes it quite easy to relegate the need for multiple or repetitive + opt()...
lines. However, I would like to know if there is a way to define defaults for geoms and scale colors. Instead of having to write ...+ scale_fill_manual()
for each plot, I'd like to be able to set it and forget it. Similarly, I'd like to be able to set geom options so I don't have to retype (or forget to retype) things like geom_text(...,size=3,color="white")
Update:
For scales, it seems at some point that there was a method:
set_default_scale("colour", "discrete", "grey")
But this function doesn't seem to exist in the most recent version of ggplot2.
There is another method for this now. You can essentially overwrite any aesthetics scale, for example:
scale_colour_discrete <- function(...) scale_colour_brewer(..., palette="Set2")
scale_fill_discrete <- function(...) scale_fill_brewer(... , palette="Set2")
Now, your aesthetics will be coloured or filled following that behaviour.'
As per: https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/w0Tl0T_U9dI
With respect to defaults to geoms, you can use update_geom_defaults
, for example:
update_geom_defaults("line", list(size = 2))
这篇关于设置geom和scale ggplot2的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!