I am trying to put error bars in stacked bar chart, but error bars are not ordered in correct place. I would be very grateful if someone can explain how to make this?
library(reshape2)
library(ggplot2)
library(plyr)
library(gridExtra)
X<- data.frame(Treatment= c("B350", "B450", "B700", "B700a", "Comp", "FS", "BW_Fluid", "BW_Solid"),
Sample = c("Biowaste", "Biowaste", "Biowaste", "Biowaste", "Biowaste", "Biowaste", "Biowaste","Biowaste"),
C_loss = c("Soil", "Production"),
C_release_percent = c(5.97, 11.9, 3.00, 2.04, 4.95, 46.85, 38.4, 20.69, 65, 78, 70, 81, 70, 0, 45, 30),
Soil = c(5.97, 11.9, 3.00, 2.04, 4.95, 46.85, 38.4, 20.69),
Production = c(65, 78, 70, 81, 70, 0, 45, 30),
CI = c(2.60, 0.51, 0.73, 0.04, 0.81, 2.50, 1.38, 2.00,3, 3, 3.5, 0.5, 2, 0, 2, 2))
p=ggplot(data, aes(x=Treatment, y=C_release_percent, fill=C_loss)) +
theme(legend.position="none")+
geom_bar(colour="black", position="stack", stat="identity")+
geom_errorbar(aes(ymax = C_release_percent + CI, ymin = C_release_percent - CI), position = "identity", size=0.5, width = 0.2)+
labs(x="Amendments", y=expression(C~release~~~percent), title="A) Biowaste")+
png(file="grafic1.png",height = 125, width = 150, unit ="mm", res = 300)
(mfrow=c(1))
grid.arrange(p, ncol = 1)
dev.off()