添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am using stat_compare_means() to carry out an anova. I need to also carry out the post-hoc Tukey test and would like to add p value comparisons to the figure, as is possible with the Kruskal-Wallis test.

So currently Kruskal-Wallis, followed by the post-hoc Dunn test can be implemented as:

my_comparisons <- list( c("0.5","1"),c("1","2"),c("0.5","2"))
df <- ToothGrowth
ggbarplot(data=df,"dose","len", add = c("mean_se")) +
stat_compare_means(comparisons = my_comparisons)

I am picturing the code for anova followed by Tukey test looking something like this:

my_comparisons <- list( c("0.5","1"),c("1","2"),c("0.5","2"))
df <- ToothGrowth
ggbarplot(data=df,"dose","len", add = c("mean_se")) +
stat_compare_means(method="anova", comparisons = my_comparisons)

Best wishes

for pairwise-comparison between groups, you need to specify method = "t.test" (Instead of anova) or method = "wilcox.test"

my_comparisons <- list( c("0.5","1"),c("1","2"),c("0.5","2"))
df <- ToothGrowth
ggbarplot(data=df,"dose","len", add = c("mean_se")) +
    stat_compare_means(method="t.test", comparisons = my_comparisons)
# Tukey HSD library( rstatix ) # https://github.com/kassambara/rstatix stat.test <- aov( len ~ dose , data = df ) % > % tukey_hsd()
# A tibble: 3 x 8
   term group1 group2 comparison estimate  conf.low conf.high   p.adj
1  dose    0.5      1      1-0.5    9.130  5.901805 12.358195 2.0e-08
2  dose    0.5      2      2-0.5   15.495 12.266805 18.723195 1.1e-11
3  dose      1      2        2-1    6.365  3.136805  9.593195 4.2e-05
# Visualize
library(ggpubr)
ggboxplot(df, x = "dose", y = "len") +
  stat_pvalue_manual(
    stat.test, label = "p.adj", 
    y.position = c(29, 35, 39)
  ropolomx, EmilioEm, RosarioIacono, Ryxicon, guatavita, millerh1, MichaelPeibo, leowill01, biobibibi, angelolimeta, and 4 more reacted with thumbs up emoji
  bernardojoconnor and Minh-AnhHuynh reacted with hooray emoji
    All reactions