通过变量设置 ggplot 主题

rmf*_*rmf 5 r ggplot2

如何使用变量更改主题?

library(ggplot2)
ggplot(iris,aes(Sepal.Length,Petal.Width))+
  geom_point()
Run Code Online (Sandbox Code Playgroud)

我可以

ggplot(iris,aes(Sepal.Length,Petal.Width))+
  geom_point()+
  theme_bw()
Run Code Online (Sandbox Code Playgroud)

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

var1 <- "theme_bw"
var2 <- "theme_grey"
Run Code Online (Sandbox Code Playgroud)

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

小智 3

Theme <\xe2\x80\x93 "theme_bw()"    \neval(parse(text=as.character(Theme)))\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n