const-ae/ggsignif

Types of non-parametric tests available

Saadi4469 opened this issue · 1 comments

Hello sir,

Are the Kruskal-Wallis (K-W) and Kolmogorov- Smirnov (K-S) tests available in the package with geom_signif?

Yes, both work out of the box

library(ggplot2)
library(ggsignif)
# Kolmogorov-Smirnov works out of the box
ggplot(mpg, aes(class, hwy)) +
  geom_boxplot() +
  geom_signif(comparisons = list(c("compact", "midsize")), textsize=6,
              test = ks.test) 
#> Warning in (function (x, y, ..., alternative = c("two.sided", "less",
#> "greater"), : cannot compute exact p-value with ties

# As does the kruskal.test
ggplot(data.frame(g = rep(LETTERS[1:2], 5), y = rnorm(10)), 
       aes(x = g, y = y)) +
  geom_boxplot() +
  geom_signif(comparisons = list(c("A", "B")), textsize=6,
              test = kruskal.test)

# When you provide a function you can do any calculation you like
ggplot(mpg, aes(class, hwy)) +
  geom_boxplot() +
  geom_signif(comparisons = list(c("compact", "midsize")), textsize=6,
              test = function(x, y){
                # Your custom test
                p_val <- 0.2
                list(p.value = p_val)
              })

Created on 2020-11-26 by the reprex package (v0.3.0.9001)

You just have to provide the base R functions. Or if you want to do something custom, you can provide your own function.