【发布时间】:2019-10-20 12:50:45
【问题描述】:
我以 mtcars 数据集为例来运行下面的代码。
library(ggplot2)
library(ggpubr)
ggboxplot(mtcars, x = "cyl", y = "drat", fill = "cyl",
facet.by = "am", width = 0.5, outlier.shape = NA,
bxp.errorbar = TRUE, bxp.errorbar.width = 0.2) +
stat_compare_means(aes(label = ifelse(p < 1.e-4,
sprintf("p = %2.1e", as.numeric(..p.format..)),
sprintf("p = %5.4f", as.numeric(..p.format..)))),
method = "wilcox.test", paired = FALSE)
我无法修改它以实现以下目标。在每个方面,我只想添加两个 wilcox.test p 值,一个比较 cyl=4 和 cyl=6,另一个比较 cyl=4 和 cyl=8。然后,我希望每个 p 值分别位于 cyl=6 和 cyl=8 框上方。
我喜欢使用 ggsignif 包,但我需要将此示例推断为 9 次比较,这使得 ggsignif 不太合适(比较栏占用太多空间)。
感谢您的任何建议。
【问题讨论】:
-
谢谢,我忘了添加“库”。现在添加到编辑版本中。
标签: r ggplot2 boxplot p-value ggpubr