ggpubr stat_compare_means:显示具有两个分组变量的显着性水平

时间:2018-10-09 14:41:06

标签: r ggplot2 statistics visualization ggpubr

我正在尝试使用ggpubr的{​​{1}}可视化显着性水平(星号)。我遇到以下问题:与stat_compare_means()相对,您无法将分组变量添加到比较中。 示例:

compare_means()

plot 如您所见,显着性水平不会显示在所有条形上方,而只会显示在不同剂量上方,因为ggpubr不能区分不同的补给。

还有什么方法可以与这些(子)集进行比较?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以尝试

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))}

enter image description here

通过添加map_signif_level = TRUEmap_signif_level = c("***"=0.001, "**"=0.01, "*"=0.05),,您将获得 enter image description here

相关问题