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")))
stat_compare_means()
无法针对每个类别分别进行成对比较。
答案 0 :(得分: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")