Rescaling y-axis in facets with buffer
08:20 30 Apr 2026

This Q&A solves the problem of having free y-scales across facets while always including 0.

However, in the resulting plot, the data sticks to the top of the plot. Is it possible to add some flexible buffer to the y-scale? In my case, this is particularly tricky, as the facets differ in scale quite a lot. I tried playing with expand, but since it adds a buffer relative to the data (5 %-steps), it either does nothing for the one facet or adds an extreme buffer to the other one.

dat <- data.frame(date = c(1:5, 1:5),
                  type = rep(c("A", "B"), each = 5),
                  value = c(4500, 4800, 4600, 4900, 4700,
                            150, 151, 150, 140, 139)
)

library(ggplot2)

dat |> 
  ggplot(aes(date, value, group = type)) +
  geom_line() +
  scale_y_continuous(limits = c(0, NA)) +
  facet_wrap(~type, scales = "free_y")

enter image description here

with expand = c(0,10):

enter image description here

with expand = c(0,100):

enter image description here

r ggplot2 facet-wrap