0

I have been trying to plot a series of boxplots by using the ggboxplot() function associated with stat_compare_means - by using stat_compare_means() - without much success. When I don't try to fix the limits of both x and y axes, I am able to plot everything in the why I want. However, I have to fix limits of the y axis in order to make my boxplots comparable across different areas/samples. When I do fix these limits, the top portion of my plots gets cut off and I can't see the mean values comparisons' significance levels.

The code I'm using to produce the boxplots without fixing y axis limits is the following:

p1 <- ggboxplot(temp3[which(temp3$Nucleus == "Bolivia"),], x = "Biome", y = 
"pH",
          color = "Biome", add = "jitter", shape = "Biome",
          palette = c("springgreen4", "blue", "gray50"))
p2 <- ggboxplot(temp3[which(temp3$Nucleus == "Brazil"),], x = "Biome", y = 
"pH",
                color = "Biome", add = "jitter", shape = "Biome",
                palette = c("springgreen4", "blue", "gray50"))
p3 <- ggarrange(p1 + stat_compare_means(comparisons=my_comparisons),
            p2 + stat_compare_means(comparisons=my_comparisons),
            labels = c("Bolivia", "Brazil"),
            ncol = 2, nrow = 1)

And this is how I've been trying to fix the y-axis' limits so I can have the same limits for all of my boxplots:

p1 <- ggboxplot(temp3[which(temp3$Nucleus == "Bolivia"),], x = "Biome", y = 
"pH",
          color = "Biome", add = "jitter", shape = "Biome",
          palette = c("springgreen4", "blue", "gray50"))
p2 <- ggboxplot(temp3[which(temp3$Nucleus == "Brazil"),], x = "Biome", y = 
"pH",
                color = "Biome", add = "jitter", shape = "Biome",
                palette = c("springgreen4", "blue", "gray50"))
p1.1 <- ggpar(p1, ylim = c(3,9), ylab = "pH")
p2.1 <- ggpar(p2, ylim = c(3,9), ylab = "pH")
p3 <- ggarrange(p1.1 + stat_compare_means(comparisons=my_comparisons),
            p2.1 + stat_compare_means(comparisons=my_comparisons),
            labels = c("Bolivia", "Brazil"),
            ncol = 2, nrow = 1)

Using ggarrange() did deal with the axes properly, but now I can't see all of the pairwise mean comparisons I have on top of my boxplots. What should I do in order to deal with this problem?

Any help is much appreciated.

Thanks,

Pedro

  • The my_comparisons object is a list with the pairwise comparisons I want to make. It was generated by using the following line: my_comparisons <- list(c("Moist Forest","Savanna"),c("Savanna","SDTF"), c("Moist Forest","SDTF")) – PedroMiranda Apr 30 '18 at 20:28
  • You need to share your data & result (plot). See more here [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Tung Apr 30 '18 at 23:23
  • I know. My lack of reputation does no allow me to do that though... – PedroMiranda May 01 '18 at 14:25

0 Answers0