使用带有gpubr的stat_compare_means指定wilcox.test替代方法

时间:2017-10-05 14:29:11

标签: r ggplot2 ggpubr

我正在使用R中gpubr的stat_compare_means()绘图功能,我试图为wilcox.test指定一个左尾(或替代="更少")规范。不幸的是,我无法让这个功能让我有能力这样做。

是否有人可以协助指定替代方案?

我在gpubr github帐户中列出了一个问题,但尚未收到有关此问题的反馈。

任何想法都会很棒。

MWE如下:

library(dplyr)
library(ggpubr)
library(ggplot2)

Mockdata <- bind_cols(data.frame(date = rep(seq(as.Date("2003/01/01"), as.Date("2003/12/01"), "months"), 6)) %>% arrange(date),
                  data.frame(Universe = rep(c("SPEURO", "SP500", "World"),24), Measure = rep(c("EBITDA", "GM"), 36), Value = rnorm(72, 5, 2))) %>% mutate_at(.vars= vars(Measure, Universe), .funs = funs(as.character))        

Median <- Mockdata %>% group_by(Universe, Measure) %>% summarise(Median.Measure = median(Value)) %>% filter(Universe == "JALSHAll")

# Boxplot:
ggboxplot(Mockdata, x = "Universe", y = "Value", color = "Universe", add = 
"jitter", legend = "none", facet.by = "Measure", )  +
 stat_compare_means(aes(label = paste0("KW: p = ", ..p.format..))) 

1 个答案:

答案 0 :(得分:0)

使用ggsignif包中的geom_signif查看下面的可能解决方案:

library(ggsignif) 

ggboxplot(Mockdata, x = "Universe", y = "Value", color = "Universe", add = "jitter", legend = "none", facet.by = "Measure", ) +                        
stat_compare_means(aes(label = paste0("KW: p = ", ..p.format..)), label.y.npc = "bottom") +  
geom_signif(test = "wilcox.test", test.args = list(alternative = "less", paired = TRUE), 
          comparisons = list(c("SPEURO", "SP500"), c("SPEURO", "World")),
          vjust = 0, step_increase = 0.12, map_signif_level = TRUE)

可以在test.args参数中指定其他测试参数。