在ggplot中添加默认标签 [英] Add default label in ggplot
问题描述
我想为所有图表添加一个默认标题,这样我就不必为我制作的所有图表输入默认标题.有没有一种方法可以将默认文本标签添加到主题?
I would like to add a default caption to all my charts so that I do not have to type it in for all the charts I make. Is there a way to add default text labels to a theme?
这就是我想要做的.我正在使用自己的主题(在本示例中为 theme_bw
).我想避免每次制作图表时都输入标题.有没有办法在 theme_bw()
内添加 + labs(标题=默认")
?
Here's what I'd like to do. I'm using my own theme (theme_bw
in this example). I would like to avoid typing the caption every time I make a chart. Is there a way to add + labs(caption ="Default")
inside theme_bw()
?
或者我可以同时使用 + labs(caption ="Default")
和 + theme_bw()
创建一个新对象,称为 + labs_and_theme
Or can I create a new object with both + labs(caption ="Default")
and + theme_bw()
that could be called as + labs_and_theme
ggplot(diamonds[1:20,], aes(x=carat, y=price)) +
geom_point() +
labs(caption ="Default") +
theme_bw()
推荐答案
您可以
library(ggplot2)
labs_and_theme <- list(
labs(caption ="Default"),
theme_bw()
)
ggplot(diamonds[1:20,], aes(x=carat, y=price)) +
labs_and_theme +
geom_point()
另请参见此处.
这篇关于在ggplot中添加默认标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!