下面是产生数据和ggplot2分面线图的代码,它似乎工作正常。但是,我想根据另一个(组)的值更改线的颜色,这在当前不在我的示例中。我试过添加:在一个分面线图中按分组变化线条,每个分面只有一条线
+element_line(color=combined$group))
但它没有改变任何东西。我正在尝试做什么?再次,我想在每个方面只保留1行,但根据“组”的值更改颜色。在此先感谢您的帮助!
require(ggplot2)
Year<-c(rep(2012,10),rep(2013,10),rep(2014,10))
MULTDV<-rnorm(30)
Construct<-factor(rep(1:10,3))
group<-rep(c(rep(1,5), rep(2,5)),3)
combined<-as.data.frame(cbind(Year, MULTDV, Construct, group))
qplot(factor(Year), MULTDV, data=combined, xlab=NULL, ylab=NULL, stat="identity") + stat_summary(fun.y=mean, colour="steelblue3", geom="line", aes(group=1))+facet_wrap(~Construct, nrow = 2)