ggplot2: Put multi-variable facet_wrap labels on one line

beeprogrammer picture beeprogrammer · May 10, 2016 · Viewed 19.5k times · Source

I am using facet_wrap to split my scatter plot as

facet_wrap(x~y+z)

This generates 22 plots in my case as desired. However, label for each of those 22 plots is displayed in 3 rows (x, y and z) which unnecessarily consumes the space in the window and squishes the plots into a small area. I would rather want my plots to be bigger in size. Since variables y and z are short, I would like to display them in same row instead of two.

I looked into the labeller options but none of them seem to do what I would want. I would appreciate any suggestions here.

Answer

nulptr picture nulptr · May 17, 2016

In this case you might also consider label_wrap_gen():

p <- ggplot(mtcars, aes(wt,mpg)) + geom_point() 
p + facet_wrap(cyl~am+vs, labeller = label_wrap_gen(multi_line=FALSE))

For more details see also here and here.