I want to have the strip text along the vertical axis in facet_grid()
in ggplot2 such that
- the text reads horizontally (i.e.,
angle = 0
), - the text goes over multiple lines, and
- part of the text is italicized
When I use labeller = label_parsed
, however, apparently the final line of the strip text is vertically centered, and the entire strip text is not well-adjusted positionally.
set.seed(1)
d <- data.frame(
x = rnorm(20),
y = rnorm(20),
f1 = rep(letters[1:2], each = 10),
f2 = rep(letters[1:2], 10)
)
levels(d$f2) <- c(
"a" = expression(paste("short label")),
"b" = expression(paste("Long and\npartly italicized\nlabel over\nmultiple", italic("lines")))
)
ggplot(d, aes(x, y)) +
geom_point() +
facet_grid(f2 ~ f1, scale = "free_y", labeller = label_parsed) +
theme(strip.text.y = element_text(angle = 0))
Is there a way to fix this? I thought about using vjust
but it unnecessarily adjusts the other label ("short label" above) as well.