作为一个更复杂的问题的一部分,我试图从列表中获取一个匹配我想要绘制的变量的字符串。
# http://www.cookbook-r.com/Graphs/Plotting_distributions_(ggplot2)/
set.seed(1234)
df <- data.frame(cond = factor( rep(c("A","B"), each=200) ),
rating = c(rnorm(200),rnorm(200, mean=.8)))
library(ggplot2)
myList <- list(something=c("rating", "foo1"),
else=c("foo2", "foo3"))
myList[[1]][1] # [1] "rating"
# does not work
ggplot(df, aes(x=myList[[1]][1])) + geom_histogram(binwidth=.5)
# works
ggplot(df, aes(x=rating)) + geom_histogram(binwidth=.5)
我想从列表中获取rating
而不是直接输入。任何想法如何实现这一目标?