I'm creating multiple ggplot2
plots with a "broken" Y axis using ggbreak::scale_y_break
, and exporting these to a single PDF document using gridExtra::marrangegrob()
and ggsave()
. It turns out that when saving, the broken Y axis is in fact ignored. Here is some synthetic sample code:
library(tidyverse)
suppressMessages(library(ggbreak))
library(gridExtra)
d <- tibble(val = c(rep(1, 10000), rep(2, 100), rep(3, 50)))
plt <- d |> ggplot(mapping = aes(x = val)) +
geom_histogram(bins = 3, color = "white") + theme_light() +
scale_y_break(breaks = c(150, 9950))
plt
plts <- list(plt, plt)
ggsave(filename = "test.pdf", plot = marrangeGrob(grobs = plts, nrow = 1, ncol = 1))
The plot plt
looks as follows:
In the PDF, however, it looks like this:
What am I doing wrong? Is this a bug, and if so, in which of the involved packages? Thanks!