首页 > 解决方案 > ggplot条形图问题的p值

问题描述

我正在尝试将 p 值添加到通过 ggplot 生成的条形图中,但我不断收到此错误:FUN(X[[i]], ...) 中的错误:找不到对象 'Category2'

任何帮助,将不胜感激!谢谢。

stat.test <- compare_means(Sigma2 ~ Category2, data = data, method="t.test")
p4<- ggplot(df3, aes(x=Category2, y=Sigma2, fill=Category2)) + 
      geom_bar(stat="identity", color="black", position=position_dodge()) +
      geom_errorbar(aes(ymin=Sigma2-se, ymax=Sigma2+se), width=.2, position=position_dodge(.9)) +
      labs(title="Site 1", x="", y = "")+
       theme(panel.background = element_blank()) +
       theme(legend.title = element_blank()) +  
       theme(legend.position="none") +
       theme(plot.title = element_text(size = 10,hjust = 0.5)) +
       theme(panel.border = element_rect(colour = "black", fill=NA, size=1)) +
       scale_fill_manual(values=c("springgreen4","violetred4")) +
       coord_cartesian(ylim=c(0.03,0.06)) + 
       stat_pvalue_manual(stat.test, label = "p.adj", tip.length = 0.01,y.position = 22) + 
       scale_y_continuous(expand = c(0, 0))

标签: rggplot2p-value

解决方案


推荐阅读