r语言 - 通过变量设置 ggplot 主题


如何使用

变量更改主题?

library(ggplot2)
ggplot(iris,aes(Sepal.Length,Petal.Width))+
  geom_point()

我能做到

ggplot(iris,aes(Sepal.Length,Petal.Width))+
  geom_point()+
  theme_bw()

相反,如果我的主题是在变量中定义的,

var1 <- "theme_bw"
var2 <- "theme_grey"

我可以使用它来设置主题吗?

ggplot() + get("theme_bw")()

在上面发布baptiste的答案,因为我不希望这个问题得不到回答。

Theme <– "theme_bw()"    
eval(parse(text=as.character(Theme)))

这是另一种方法,因为我在使用get时遇到了错误。

最新更新