我需要为每组中的每个条形图绘制一个具有不同误差条的分组条形图。我已设法绘制图表并添加误差线,但它们未在图表上正确定位(见下文)
我知道我知道我需要以某种方式告诉错误栏他们需要连接哪种基因型,但我不太确定如何。我试图使用这个:Grouped barplot in R with error bars但不能解决不同的问题。
代码:
ggplot(data=leaf_level) +
geom_bar(aes(x=factor(DAS), y=Total_cells_m, fill=factor(Genotype)),
position=position_dodge(), stat="identity", colour="black") +
geom_errorbar(data=leaf_level, aes(x=factor(DAS), ymin=Total_cells_m-
Total_cells_se, ymax=Total_cells_m+Total_cells_se, width=0.1),
position=position_dodge(2)) +
theme_bw() +
scale_fill_brewer(palette = "Set2", breaks=c("WT","da1-1","bb","da1-1bb")) +
guides(fill=FALSE) +
xlab("Days after stratification") + ylab("Mean cell number")
数据样本:
DAS Genotype Total_cells_m Total_area_se Cell_density_m Total_cells_se Total_area_se.1 Cell_density_se
1 7 wt 784.250 60503.07 0.013013254 169.7647 13399.47 0.000255982
2 7 da1 1688.333 100423.70 0.017028424 126.3544 12609.61 0.000897470
3 7 bb 1723.667 135049.71 0.012741455 231.1077 17410.68 0.000275997
4 7 da1bb 1626.667 94975.07 0.017344191 368.7702 24144.72 0.000430231
5 8 wt 2211.667 228633.44 0.009938105 227.8869 41014.18 0.000755033
6 8 da1 4468.750 367415.43 0.012298110 202.0942 28191.02 0.000753529