首页 > 解决方案 > ggplot中多重比较的条件p值

问题描述

我被要求使用以下表格在箱线图上显示 p 值:

我设法使用此代码使其仅用于比较两组:

ggplot(ToothGrowth, aes(x=supp, y=len))+
  geom_boxplot()+
  stat_compare_means(mapping=aes(x=supp, y=len, label = ifelse(p > 0.05 & p < 0.09, 
                                                               as.numeric(..p.format..), as.character(p.signif))), 
                     method="t.test", paired=FALSE,  
                     symnum.args=list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1),
                                      symbols = c("****", "***", "**", "*", "")))

简单比较的工作图

现在我有一些带有多重比较的图。我在那里使用comparisons = list(c(1,2), c(1,3), c(2,3))

不幸的是,一旦我添加了比较参数,上述解决方案就不再有效。

ggplot(ToothGrowth, aes(x=supp, y=len))+
  geom_boxplot()+
  stat_compare_means(mapping=aes(x=supp, y=len, label = ifelse(p > 0.05 & p < 0.09, 
                                                               as.numeric(..p.format..), as.character(p.signif))), 
                     method="t.test", paired=FALSE, comparisons = list(c(1,2)),
                     symnum.args=list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1),
                                      symbols = c("****", "***", "**", "*", "")))

带有比较参数的图表不起作用

理想情况下,我还想在 p > 0.09 时删除括号。

我感谢任何帮助,否则我将需要手动放置符合标准的比较。

标签: rggplot2

解决方案


推荐阅读