在ggplot中添加默认标签

时间:2017-06-18 16:04:33

标签: r ggplot2

我想为我的所有图表添加一个默认标题,这样我就不必为我制作的所有图表输入它。有没有办法为主题添加默认文本标签?

这就是我想做的事情。我使用自己的主题(本例中为theme_bw)。我想避免每次制作图表时都输入标题。有没有办法在+ labs(caption ="Default")内添加theme_bw()

或者我可以使用+ labs(caption ="Default")+ theme_bw()创建一个可以被称为+ labs_and_theme的新对象

ggplot(diamonds[1:20,], aes(x=carat, y=price)) + 
  geom_point() +
  labs(caption ="Default") +
  theme_bw()

enter image description here

1 个答案:

答案 0 :(得分:4)

你可以做到

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() 

另见here

相关问题