如何用内容/值替换变量?请参阅下面的示例代码。
###########SET my plotting variable##########################
plot_var_y<-'var1'
plot_var_x<-'var2'
####################EVALUATE THE FOLLOWING##################
temp$plot_var_y
# The above expression evaluates to null which is not what I want.temp$var1 is what I was looking for
plot1<-ggplot(aes(y = plot_var_y, x = as.factor(plot_var_x), fill = no_of_heads), data =temp) +
geom_boxplot()+stat_summary(fun.y=mean, geom="line",aes(group=1),colour=I("red"))+stat_summary(fun.y=mean, geom="point",shape=18,size=3)+xlab("position")
答案 0 :(得分:1)
使用aes_string
代替aes
尝试
plot1<-ggplot(aes_string(y = plot_var_y, x = as.factor(plot_var_x), fill = no_of_heads), data =temp) +
geom_boxplot()+stat_summary(fun.y=mean, geom="line",aes(group=1),colour=I("red"))+stat_summary(fun.y=mean, geom="point",shape=18,size=3)+xlab("position")