0

I'm creating boxplots and scatterplots with ggplot2, then arranging them with ggarrange. It works well, but I've encountered a problem. I have outliers in the data and for better visual representation I've incorporated scale breaks.

For some reason these scale breaks disappear when I then use ggarrange. Is there a simple way to solve this?

Below I've included some code with simple vectors that shows the problem. These are boxplots only. The first window will have scale breaks, the second window does not, and in the third window (made with ggarrange) the scale break is gone.

library(ggplot2)
library(ggbreak)
library(ggpubr)

vec1 <- c(1:50, 500)
data <- data.frame(vec1)
vec2 <- c(10:60)
data2 <- data.frame(vec2)

windows()
a <-ggplot() +
    geom_boxplot(data=data, aes(x="1", y=vec1)) + scale_y_break(c(100, 550)) + theme(legend.position="none")
a

windows()
b <-ggplot() +
    geom_boxplot(data=data2, aes(x="1", y=vec2)) + theme(legend.position="none")
b

windows()
ggarrange(a, b, labels = c("A", "B"), ncol = 2)
Amlin
  • 1
  • 1
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and that can be used to test and verify possible solutions. – MrFlick Aug 09 '23 at 13:53
  • Thank you. I'm a novice here (and with programming), but I will try my best to extend the question with an example and a sample input. – Amlin Aug 10 '23 at 06:21
  • What package does `scale_y_break` and `ggarrange ` come from? Those are not `ggplot2` functions. – MrFlick Aug 10 '23 at 13:53
  • *face palm*. I thought I had it this time... Thank you for your patience! I'll edit again. – Amlin Aug 10 '23 at 18:23

0 Answers0