为ggplot2中的多个主题元素分配相同的值

Assign the same value to multiple theme elements in ggplot2

我觉得这是一个很简单的问题,但我找不到任何地方问过它。我也无法在文档中找到任何内容。

ggplot2中是否可以为多个[=3=​​]元素分配相同的值?例如,我可以这样写我的主题声明:

 theme(axis.text = element_text(colour = "gray25"), 
        axis.text.x = element_text(angle = 45, hjust = 1),
        line = element_line(colour = "gray25"),
        strip.text = element_text(face = "bold"),
        legend.title = element_text(colour = "gray25"),
        legend.text = element_text(colour = "gray25"),
        plot.title = element_text(colour = "gray25", face="bold",vjust=2))

但这似乎很重复。难道没有类似连词的东西可以给多个元素赋予相同的值吗?例如这样的东西。

   theme(axis.text & legend.title & legend.text & plot.title = element_text(colour = "gray25"),
        labels bold 
        axis.text.x = element_text(angle = 45, hjust = 1),
        strip.text = element_text(face = "bold"),
        plot.title = element_text(face="bold",vjust=2))

?theme, you find that "Theme elements can inherit properties from other theme elements". For all individual theme elements, you find which element they inherit from. Thus, you can try to change as many properties as possible in the 'top level' in order to avoid redundancy. You can read more in the official theme vignette 中,您还可以找到元素之间继承的可视化:

如果您有一个 theme 希望重复使用(例如针对特定期刊或出版商),您可以自定义并保存您自己的 themes。例如,您可以从 default theme 开始,进行更改、保存并通过在绘图代码末尾添加 + theme_bw_custom(或任何您命名的名称)来使用它。

另请参阅 ggthemes,这可以作为创建您自己的 themes 的起点。