将自己的 ggplot 主题保存在包中并记录下来
saving own ggplot theme in package and document it
我在创建图表时一直对 ggplot 进行一些自定义更改。我想在我的包中提供这个主题,但我不确定如何保存和记录它。它不是数据集也不是函数。这样做的首选方式是什么?
my_theme <- theme_bw() + theme(plot.title=element_text(vjust=1))
ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme
所以我想在文档中添加 my_theme
。
我刚刚通过查看 theme_bw
意识到我可以用同样的方式做到这一点:
my_theme <- function (base_size = 12, base_family = "") {
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(plot.title=element_text(vjust=1))
}
ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme()
这样我就可以记录我的功能...
我在创建图表时一直对 ggplot 进行一些自定义更改。我想在我的包中提供这个主题,但我不确定如何保存和记录它。它不是数据集也不是函数。这样做的首选方式是什么?
my_theme <- theme_bw() + theme(plot.title=element_text(vjust=1))
ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme
所以我想在文档中添加 my_theme
。
我刚刚通过查看 theme_bw
意识到我可以用同样的方式做到这一点:
my_theme <- function (base_size = 12, base_family = "") {
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(plot.title=element_text(vjust=1))
}
ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme()
这样我就可以记录我的功能...