0

I am using the stat_compare_means() plotting function from gpubr in R, and I'm trying to specify a left-tailed (or alternative = "less") specification for the wilcox.test. Unfortunately I cannot get the function to give me the ability to do so.

Could anyone possibly assist in specifying an alternative?

I listed an issue on the gpubr github account but have not yet received feedback on this.

Any ideas would be great.

MWE follows:

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..))) 
Nick
  • 3,262
  • 30
  • 44

1 Answers1

0

See possible solution below using geom_signif found in the package ggsignif:

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)

Additional test arguments can be specified in the test.args parameter.

Christiaan
  • 26
  • 3