2
votes

I would like to compute an anova only including gr1-gr3 excluding gr4. Is this possible using stat_compare_means()?

x   value
gr1 3.543
gr1 2.12
gr1 4.56
gr2 3.3
gr2 2.12
gr2 4.1
gr3 3.32
gr3 2.3
gr3 3.3
gr4 3.325
gr4 2.355
gr4 3.34

library(ggpubr)
ggplot(df(aes(x,value)) + geom_boxplot() + stat_compare_means()
1
You can always filter it out. df %>% filter(x != "gr4").TheRimalaya
I will keep the group in the plotuser2300940

1 Answers

3
votes

This might help. There is a comparisons argument which you can use for this.

ggplot(dta, aes(x, value)) + 
    geom_boxplot() + 
    stat_compare_means(comparisons = list(1:2, 2:3, c(1, 3), c(1, 2, 3)))

enter image description here

EDIT: For ANOVA

ggplot(dta, aes(x, value)) + 
    geom_boxplot() + 
    stat_compare_means(method = "anova", label.y = 4.8, 
                       data = dta %>% filter(x != "gr4"))

enter image description here