y axis break with facets

Hello. I am trying to produce a plot with a discontinuous y-axis but can't get the facet titles to only show once:

Example Data:

> ggplot(mpg, aes(displ, cty)) +
+     geom_point() +
+     facet_grid(. ~ drv)

After much digging it appears that this is impossible in ggplot2, but I have discovered the gg.gap package. However, this package replicates the facet titles for each segment of the plot. Let's say I want a break in the y axis from 22-32 as follows:

gg.gap(plot = p,
       segments = c(22, 32),
       ylim = c(0, 35))


Nirgrahamuk's solution seems to work for bar plots, but does not work when plotting with facets. Facet titles still appear for each plot segment. I would be grateful for any insight of help anyone could provide! I'm stumped.

I know this is possible if I plot in base R, but given other constraints I am unable to do so.

You can have any facet titles you want with a labeller function:
Construct labelling specification — labeller • ggplot2 (tidyverse.org)

1 Like

Thanks @martin.R ! I am trying to remove the facet titles for the bottom row though - I don't see that I can do this with the labeller function but maybe I'm missing something?

they might be a facet grid solution or facet_zoom

mpg$city_below_22 <- ifelse(mpg$cty< 24,"below 24","above 32")
mpg<- mpg %>%
filter(cty < 24 | cty >32)

ggplot(mpg, aes(displ, cty)) +
geom_point() +
facet_grid(city_below_22 ~ drv,scales="free",space="free")

Thanks @smouksassi! That did the trick :slight_smile: