why the average value changed in Qiime2R

Dear all,
I use the qiime2r to make a barplot,but I foun the value the bar displayed is wrong. The mean of PLA CK should be 4.06, but it is about 5.5 in bar plot.


My codes are here

metadata<-
metadata %>%
left_join(shannon)
head(metadata)

levels (metadata$"Fertilizer-type")= c("CK", "CF", "OF")
filter_data<- metadata %>%
filter(Source =="Plastic")
filter_data$Plastic-type <- factor(fd$Plastic-type, levels = c('LDPE', 'PLA', 'PBS', 'PBAT'))

p1 <- filter_data %>%
filter(!is.na(shannon)) %>%
ggplot(aes(x=Fertilizer-type, y=shannon, fill=Fertilizer-type)) +
stat_summary(geom="bar", fun.data=mean_se, color="black") + #here black is the outline for the bars

stat_summary(geom="errorbar", fun.data=mean_se,colour="black", width=0.1,size=1) +
coord_cartesian(ylim=c(2,7.5)) +
facet_grid(~Plastic-type) +
xlab("Fertilizer Usage") +
ylab("Shannon Diversity") +
theme_q2r() + # try other themes like theme_bw() or theme_classic()
scale_fill_manual(values=c("#FF5A5F","#FFB400", "#007A87")) + #specify custom colors
theme(legend.position="none") #remove the legend as it isn't needed
p1
head(p1)

Hello @YuZhang,

EDIT: I think I found your problem!

While those samples are labeled PLA-CK, they are listed as CF in the Fertilizer-type column and so would be appearing in the CF bar on the graph.

Once you correct the metadata, it should work as intended! :bar_chart:


Show original post:

Thank you for posting both your code and your graph.

The function mean_se() should be returning the mean value, so I'm not sure why it's broken. Could you post the output of this code?

filter_data %>%
  filter(!is.na(shannon)) %>%
  select(Fertilizer-type, shannon) %>%
  filter(Fertilizer-type == "CK", Plastic-type == "PLA")

This will let us check that the values used for graphing match the 5 values in your screenshot that have a mean of 4.064.

Colin

2 Likes

Thanks,I will check it