我正在使用下面的代码绘制一系列方法和标准偏差,并尝试使用geom_ribbon来显示sd' s,见下文。
由于重叠很重要,我想在色带上添加一个边框,这个边框与相应的变量颜色相同但是是一条虚线,但我无法弄清楚代码在哪里会去。我知道"颜色"和"线型"以某种方式涉及命令......
谢谢!
graph.msd <- ggplot(data=g.data, aes(x=quarter,y=mean,group=number))
graph.msd <- graph.msd + geom_line(aes(colour = number),size=1)+geom_ribbon(aes(ymin=mean-sd,ymax=mean+sd,fill=number),linetype=2,alpha=0.1)
答案 0 :(得分:12)
您需要将colour
的值传递给geom_ribbon
类似
graph.msd <- graph.msd +
geom_line(aes(colour = number),size=1)+
geom_ribbon(aes(ymin = mean-sd, ymax = mean+sd,
fill = number,colour = number), linetype=2, alpha=0.1)
带有可重复的示例(使用?geom_ribbon
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
library(plyr) # to access round_any
huron$decade <- round_any(huron$year, 10, floor)
ggplot(huron, aes(x =year, group = decade)) +
geom_ribbon(aes(ymin = level-1, ymax = level+1,
colour = factor(decade), fill = factor(decade)),
linetype = 2, alpha= 0.1)