2017-04-09 58 views
1

如何使用變量更改主題?通過變量設置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" 

我可以使用它來設置主題?

+2

'ggplot()+ get(「theme_bw」)()' – baptiste

+0

這有效。謝謝!你想添加它作爲答案? – rmf

回答

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

發佈baptiste的答案在上面,因爲我不想讓這個問題沒有答案。