Consider the following ggplot2 graph with long facet/strip text
broken in two lines.
The text goes outside the area devoted to facet titles.
library(ggplot2)
x <- c(1:3, 1:3)
y <- c(3:1, 1:3)
grp <- c(0, 0, 0, 1, 1, 1)
p <- qplot(x=x, y=y) + geom_line() + facet_wrap(~ grp)
grob <- ggplotGrob(p)
strip.elem.y <- grid.ls(getGrob(grob, "strip.text.x",
grep=TRUE, global=TRUE))$name
grob <- geditGrob(grob, strip.elem.y[1],
label="First line and\n second line" )
grid.draw(grob)
Is there a way to increase the height of the strip text area ?
I tried this a variety of ways but was frustrated getting the
paste(strwrap(text, width=40), collapse=" \n")to give me results for the single row of data and not concatenate the each bit of text from the entire list.I came up with a solution that worked best for me. I wrote a function like the one below. Given a dataframe
datawith columntextAfter I called this function, I just applied my
labellerfunction to thewrapped_textcolumn instead of thetextcolumn.