我有数据可以看到两种不同物种的单养和混合养殖之间的增长差异。此外,我制作了一张图表,以清晰显示我的数据。如何为小平面添加不同的线条
我想要一个有错误条的barplot,整个数据集当然会更大,但是对于这个图,这是带有barplot的手段的data.frame
。
plant species means
Mixed culture Elytrigia 0.886625
Monoculture Elytrigia 1.022667
Monoculture Festuca 0.314375
Mixed culture Festuca 0.078125
有了这个数据I中ggplot2
,其中plant
是在x轴和means
在y轴作出的曲线图,我使用的小面来划分种类。
这是我的代码:
limits <- aes(ymax = meansS$means + eS$se, ymin=meansS$means - eS$se)
dodge <- position_dodge(width=0.9)
myplot <- ggplot(data=meansS, aes(x=plant, y=means, fill=plant)) + facet_grid(. ~ species)
myplot <- myplot + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
myplot <- myplot + scale_fill_manual(values=c("#6495ED","#FF7F50"))
myplot <- myplot + labs(x = "Plant treatment", y = "Shoot biomass (gr)")
myplot <- myplot + opts(title="Plant competition")
myplot <- myplot + opts(legend.position = "none")
myplot <- myplot + opts(panel.grid.minor=theme_blank(), panel.grid.major=theme_blank())
到目前为止,这是罚款。但是,我想在两个方面添加两条不同的水平线。对于这一点,我用这个代码:
hline.data <- data.frame(z = c(0.511,0.157), species = c("Elytrigia","Festuca"))
myplot <- myplot + geom_hline(aes(yintercept = z), hline.data)
但是,如果我这样做,我得到一个情节是有两个额外的方面,其中两条水平线绘制。相反,我希望水平线被绘制在带有横条的小平面上,而不是创造出两个新的方面。任何人都知道如何解决这个问题。
我想有更清楚,如果我把这个图我现在创建:
是'abline'你在找什么? – Pop 2012-08-07 12:51:36
不,我只需要一个水平线,在给定的y坐标。然而,每个方面的价值都不相同,例如Elytrigia的水平线为0.511,Festuca的水平线为0.157。 – Marinka 2012-08-07 12:55:45
我可以建议你完全按照从控制台上剪切和粘贴你的数据集,或者使用'dput(means)'给我们提供你的数据。 – 2012-08-07 12:56:10