欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

R" ggplot2 添加校正后的 p 值。

最编程 2024-03-02 15:57:49
...

ggpubr 实现了 ggplot2 绘图添加 p 值的良好支持,但读者需要注意它是没有经常矫正的。矫正 p 值需要额外的处理。

来源:https://github.com/kassambara/ggpubr/issues/65#issuecomment-407211245[1]

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")

参考资料

[1]

https://github.com/kassambara/ggpubr/issues/65#issuecomment-407211245: https://github.com/kassambara/ggpubr/issues/65#issuecomment-407211245