How to display pairwise comparisons for two groups in a batch ggstatsplot2

Viewed 235

I have the code that I took from the example:

set.seed(123)
library(ggstatsplot)



    grouped_ggbetweenstats(
      data = dplyr::filter(ggplot2::mpg, drv != "4",displ==2),
      x = year,
      y = hwy,
      grouping.var = drv,
    )

I need to output a comparison between two groups After reading the documentation I added:

set.seed(123)
library(ggstatsplot)

# the most basic function call
grouped_ggbetweenstats(
  data = dplyr::filter(ggplot2::mpg, drv != "4",displ==2),
  x = year,
  y = hwy,
  grouping.var = drv,
  pairwise.comparisons = T,
  pairwise.display = "all",
  p.adjust.method = "BH"
)

But the display of the comparison lines between the groups did not appear. Is it possible to somehow output them in this package ? For 3 or more groups, they are output, but not for 2.

1 Answers

There is an issue on ggstatsplot's GitHub repo that answers this very question: https://github.com/IndrajeetPatil/ggstatsplot/issues/605

set.seed(123)
library(ggstatsplot)
library(ggsignif)

# displaying only one comparison
ggbetweenstats(mtcars, am, wt) +
  geom_signif(comparisons = list(c("0", "1")))
#> Warning in wilcox.test.default(c(3.215, 3.44, 3.46, 3.57, 3.19, 3.15, 3.44, :
#> cannot compute exact p-value with ties

Created on 2021-05-28 by the reprex package (v2.0.0)

You can decide whether to turn off ggstatsplot's own analysis using the argument results.subtitle. It defaults to TRUE, but if you change it to FALSE, it will show only the p-value in the pairwise comparison.

set.seed(123)
library(ggstatsplot)
library(ggsignif)

# displaying only one comparison
ggbetweenstats(mtcars, am, wt, results.subtitle = FALSE) +
  geom_signif(comparisons = list(c("0", "1")))
#> Warning in wilcox.test.default(c(3.215, 3.44, 3.46, 3.57, 3.19, 3.15, 3.44, :
#> cannot compute exact p-value with ties

Created on 2021-06-10 by the reprex package (v2.0.0)

Related