来源:https://github.com/kassambara/ggpubr/issues/65#issuecomment-407211245
library(tidyverse)
library(rstatix)
library(ggpubr)
# Pairwise t-test between groups
stat.test <- ToothGrowth %>%
group_by(dose) %>%
t_test(len ~ supp) %>%
adjust_pvalue() %>%
mutate(y.position = 35)
stat.test
# A tibble: 3 x 9
dose .y. group1 group2 statistic p method p.adj y.position
1 0.5 len OJ VC 3.1697328 0.0064 T-test 0.0128 35
2 1.0 len OJ VC 4.0327696 0.0010 T-test 0.0030 35
3 2.0 len OJ VC -0.0461361 0.9600 T-test 0.9600 35
# Create a box plot and add the p-value
p <- ggboxplot(
ToothGrowth, x = "supp", y = "len",
color = "supp", palette = "jco",
facet.by = "dose", ylim = c(0, 40)
)
p + stat_pvalue_manual(stat.test, label = "p.adj")
![](https://img.haomeiwen.com/i3884693/8dd9d6fa6acc3d17.png)
网友评论