const-ae / ggsignif

Easily add significance brackets to your ggplots
https://const-ae.github.io/ggsignif/
GNU General Public License v3.0
593 stars 43 forks source link

Types of non-parametric tests available #72

Closed Saadi4469 closed 4 years ago

Saadi4469 commented 4 years ago

Hello sir,

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

const-ae commented 4 years ago

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.