The error bar doesn show up when plotting.
Here is my original code:
aa<-structure(list(sample = c("L-FF", "L-FF", "L-FF", "L-FF", "L-FF",
"L-FF", "L-SS", "L-SS", "L-SS", "L-SS", "L-SS", "L-SS", "L-MM",
"L-MM", "L-MM", "L-MM", "L-MM", "L-MM", "L-MF", "L-MF", "L-MF",
"L-MF", "L-MF", "L-MF", "L-MS", "L-MS", "L-MS", "L-MS", "L-MS",
"L-MS"), group = c("FF", "FF", "FF", "FF", "FF", "FF", "SS",
"SS", "SS", "SS", "SS", "SS", "MM", "MM", "MM", "MM", "MM", "MM",
"MF", "MF", "MF", "MF", "MF", "MF", "MS", "MS", "MS", "MS", "MS",
"MS"), group2 = c("P0N0", "P0N1", "P1N0", "P1N1", "P2N2", "P3N0",
"P0N0", "P0N1", "P1N0", "P1N1", "P2N2", "P3N0", "P0N0", "P0N1",
"P1N0", "P1N1", "P2N2", "P3N0", "P0N0", "P0N1", "P1N0", "P1N1",
"P2N2", "P3N0", "P0N0", "P0N1", "P1N0", "P1N1", "P2N2", "P3N0"
), depth = c("Low", "Low", "Low", "Low", "Low", "Low", "Low",
"Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low",
"Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low",
"Low", "Low", "Low", "Low", "Low"), mean = c(8.43666666666667,
8.41666666666667, 8.42333333333333, 8.50333333333333, 8.34, 8.37,
8.19333333333333, 8.32, 8.34333333333333, 8.39, 8.25666666666667,
8.48, 8.34666666666667, 8.24666666666667, 8.31, 8.39333333333333,
8.24, 8.49333333333333, 8.35666666666667, 8.35, 8.51333333333333,
8.48, 8.34333333333333, 8.52666666666667, 8.34333333333333, 8.20666666666667,
8.30666666666667, 8.4, 8.12666666666667, 8.47666666666667), se = c(0.0696020433927371,
0.0926162932629988, 0.0829323686974982, 0.0545690184791495, 0.0435889894354068,
0.0802080627701062, 0.202182535788277, 0.0550757054728609, 0.0744610263456291,
0.0529150262212925, 0.0584047182264505, 0.0458257569495582, 0.0669161996662826,
0.0811035004039766, 0.0702376916856848, 0.061734197258174, 0.056862407030773,
0.0523874454850056, 0.0545690184791497, 0.138924439894498, 0.0120185042515464,
0.0568624070307733, 0.0392994204085055, 0.0762306441735284, 0.066916199666282,
0.170522074165715, 0.12387269450708, 0.0360555127546394, 0.0484194634877803,
0.0463081466314994)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -30L))
And here is my code:
library(ggplot2)
library(ggpubr)
library(readxl)
library(ggsci)
p<-ggplot(aa, aes(group,mean,fill=group2))+
geom_bar(stat="identity",width = 0.7,size=0.2,alpha=1,color='black',position="stack")+
geom_errorbar(aes(ymin =mean-se, ymax =mean + se),width=0.2,position="identity") +
theme(legend.text=element_text(family="Times",size=10))+
labs(x ='' , y = 'Organic matter (mg/kg)', fill = 'sample') +
theme_bw()+
scale_y_continuous(expand = c(0, 0), limit = c(0,60),breaks = seq(0,60,10))+
guides(fill=guide_legend(title = ''))+
theme(panel.grid = element_blank(), panel.background = element_blank())+
theme(
text = element_text(family="Times",size=14),
plot.title = element_text(family="Times",size = 14),
axis.text.x = element_text(family="Times",size = 14, colour= 'black'),
axis.text.y = element_text(family="Times",size = 14, colour= 'black'),
legend.text = element_text(family="Times",size = 14, colour= 'black'))+
theme(axis.ticks.length = unit(0.1,'cm'),
plot.margin = unit(c(0.5, 0.5, 0.5, 0.5), "cm"))
p + scale_fill_nejm()
Here is the figre I got with the code:
But the error bar doesn't show up. Here is the effect I expected:

Any suggestions are welcome! Thank you advance!


