简体   繁体   中英

ggpubr stat_compare_means: Show significance levels with two grouping variables

I am trying to visualize significance levels (asterisks) with ggpubr 's stat_compare_means() . I encountered the following issue: As opposed to compare_means() , you cannot add a grouping variable to the comparison. Example:

ggbarplot(ToothGrowth, x = "dose", y = "len", add = "mean_se", color = "supp",
fill = "supp",position = position_dodge(0.8),add.params = list(group = "supp"))+
stat_compare_means(ref.group = "0.5", group.by = "supp",label = "p.signif")

阴谋 As you can see, the significance levels are not displayed above all the bars, but only above the different doses, because ggpubr doesn't differentiate between different supps.

Is there any way to compare to these (sub)sets as well?

Thank you

You can try

library(tidyverse)
library(ggsignif)
ToothGrowth %>% 
     mutate(gr=interaction(supp, dose, sep = " ")) %>% 
    {ggplot(data=.,aes(x = gr,  y = len, fill = supp)) +
            stat_summary(fun.y = mean, geom = "bar") +
            stat_summary(aes(col = supp), fun.data = "mean_se", geom = "errorbar", width=0.6)+
            ggsignif::geom_signif(comparisons = combn(sort(unique(as.character(.$gr))),2, simplify = F),
                                  step_increase = 0.08,test = "wilcox.test", test.args = list(exact = FALSE))}

在此处输入图片说明

By adding map_signif_level = TRUE or map_signif_level = c("***"=0.001, "**"=0.01, "*"=0.05), you get在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM