在每个类别中从成对比较中添加p值

问题描述 投票:0回答:1
library(tidyverse)
library(ggpubr)

df <- tibble(
  iq = rnorm(150, 100, 15),
  condition = rep(c("A", "B"), each = 75),
  time = rep(c("t1", "t2", "t3","t1", "t2","t3"), each = 25)
)
ggbarplot(df,
          x = "condition",
          y = "iq",
          fill = "time",
          palette = "grey",
          add = "mean_se", add.params = list(group = "time"),
          position = position_dodge(0.8)) +
  stat_compare_means(aes(group = time),label = "p.signif", paired = TRUE, 
                     comparisons = list(c("t1", "t2"), 
                                        c("t1", "t3"),  
                                        c("t2", "t3")))

2 x 3 interaction bar plot

stat_compare_means()不能分别对每个类别进行成对比较。

r ggplot2 anova ggpubr
1个回答
0
投票

也许这段代码可以提供帮助:您可以先计算每次比较的p值,然后将它们添加到图中。

library(tidyverse)  
if(!require(devtools)) install.packages("devtools")  devtools::install_github("kassambara/rstatix") 
library(rstatix)     
library(ggpubr)  
stat.test <- df %>%   group_by(condition) %>%   t_test(iq ~ time) %>%   adjust_pvalue() %>%   add_significance("p.adj") %>%   mutate(y.position = 115) 
stat.test

    ggbarplot(df,
              x = "time",
              y = "iq",
              facet.by = "condition",
              fill = "time",
              palette = "grey",
              add = "mean_se", add.params = list(group = "time"),
              position = position_dodge(0.8)) +   stat_pvalue_manual(stat.test,label = "p.adj", y.position = "y.position")
© www.soinside.com 2019 - 2024. All rights reserved.