How to change from row to column major order with facet_wrap?
ggplot2, r
Solution
Use the direction `dir` parameter to `facet_wrap()`. Default is horizontal, and this can be switched to vertical:
# Horizontally
ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point() + facet_wrap(~ cyl, ncol=2)
# Vertically
ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point() + facet_wrap(~ cyl, ncol=2, dir="v")
Problem
I want to make a 2x4 array of plots that show distributions changing over time. The default `ggplot` arrangement with `facet_wrap` is that the top row has series 1&2, the second row has series 3&4, etc. I would like to change this so that the first column has series in order (1->2->3->4) and then the second column has the next 4 series. This way your eye can compare immediately adjacent distributions in time vertically (as I think they should be).