Crop strip background when combining long and short facet labels

Viewed 120

I have plot where the facet labels are very long in one category, but much shorter in the second category. However, the strip background fits the long labels, but expands too much on the shorter labels.

Let's say we have the following plot:

library(ggplot2)
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point() +
  facet_grid("Here be a very very long label" + Species ~ ., switch = "y") +
  theme(
    strip.placement = "outside",
    strip.text.y.left = element_text(angle = 0),
    strip.background = element_rect(colour = "black") # Just for indication
  )

I'm specifically interested in reducing the margin around the second layer of strips, indicated in red below:

enter image description here

I know how I would be able to construct a facet function or edit the plot at the grid graphics/gtable level, I'm just asking around to see if anyone would know of a simpler solution. I'm not looking to wrap, rotate or resize the long labels; I want to shrink the margins around the short ones.

Thanks for reading!

0 Answers
Related