1

I want to have a box plot with the significance level (e.g. ***) over each group, without a line. The comparison to generate the p value/significance level will be for each test group relative to a single control group.

I have a lot of different graphs to make, which means creating and positioning a text box manually for each will be prohibitively time consuming. Therefore, I wish to use the geom_signif function to auto calculate and position these.

I am able to create something like the following:

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
ggplot(data=ToothGrowth, aes(x=dose, y=len)) +
  geom_boxplot() +
  geom_signif(comparisons=list(c("0.5", "1"),
                               c("0.5", "2")), 
              map_signif_level=TRUE, y_position = c(40, 45))

This is fine for two or three groups, but gets messy for larger numbers of groups such as in the data set I am working with.

An alternative approach:

ggplot(data=ToothGrowth, aes(x=dose, y=len)) +
  geom_boxplot() +
  geom_signif(comparisons=list(c("0.5", "1"),
                           c("0.5", "2")), 
              map_signif_level=TRUE)

This looks awful. However, if the significance signs could be spaced to match the x-axis ticks, and preferably if the line could be removed/hidden, this would be ideal.

Can anyone demonstrate how to do this?

Brian
  • 7,900
  • 1
  • 27
  • 41
JamesCrook
  • 23
  • 1
  • 6

1 Answers1

1

May be the 'ggpubr' package may help you. See the 'Multiple pairwise tests against a reference group' section from: https://www.r-bloggers.com/add-p-values-and-significance-levels-to-ggplots/

Ivan
  • 472
  • 4
  • 15