2

I want to add significance levels in a boxplot in R. I use the function ggplot with facet_wrap. I created a graph with ggboxplot and ggarrange() from the output of pairwise comparisons test (Dunn's test after Kruskal-Wallis test). This is the graph:

Kruskal-Wallis graph 1

This is the code for the graph above:

(plot1.1 <- ggboxplot(pamT1, x = "Temperature", y = "Yield") +
  stat_pvalue_manual(pwc2, hide.ns = TRUE))
(plot2.2 <- ggboxplot(pamT2, x = "Temperature", y = "Yield") +
  stat_pvalue_manual(pwc4, hide.ns = TRUE))
(plot3.3 <- ggboxplot(pamT3, x = "Temperature", y = "Yield") +
  stat_pvalue_manual(pwc6, hide.ns = TRUE))
(plot4.4 <- ggboxplot(pamT4, x = "Temperature", y = "Yield") +
  stat_pvalue_manual(pwc8, hide.ns = TRUE))

ggarrange(plot1.1, plot2.2, plot3.3, plot4.4, 
          labels = c("A", "B", "C", "D"),
          ncol = 2, nrow = 2)

However, I would like to get a figure like this which I made with ggplot + geom_boxplot() and facet_wrap(). I've added the letters in it myself. Ideally, I would add the significance signs * and ** in the geom_boxplot(), but I have not been able to create such a graph.

Image with facet_wrap where I want the significance * in 2

This is the code I used for the facet boxplot

ggplot(pam2, aes(x=Temperature, y=Yield, fill=Temperature)) + 
  geom_boxplot(alpha=0.9) +
  facet_wrap(pam2$Time, scales="free_y", labeller = labeller(Time=labels)) + 
  theme(legend.position="none") +
  scale_fill_manual(values=c("dodgerblue4", "dodgerblue", "grey70", "firebrick1", "firebrick")) +
  labs(y="Photosynthetic yield", x=xlab, fill=expression("Temperature " ( degree*C))) +
  theme_classic() +
  theme(legend.position="bottom") +
  scale_y_continuous(labels = label_number(accuracy = 0.01))

I don't seem to be able to use stat_pvalue_manual() in the geom_boxplot() function. Can anyone help me with the correct piece of code I could use for this?

Thanks in advance!

Adam Quek
  • 6,973
  • 1
  • 17
  • 23
Chiara
  • 33
  • 3

0 Answers0