Set number of columns (or rows) in a facetted plot

Viewed 45515

I have a facetted plot like this:

ggplot(mtcars, aes(x = hp, y = mpg)) +
  geom_point() +
  facet_grid(. ~ carb)

enter image description here However, the graph is too wide to be clearly read.

I'd like to be able to take the three rightmost locations and place them under the three leftmost, i.e. the facets should be in three columns * two rows like this.

1   2   3

4   5   6

Is it possible to set the layout of the facets, i.e. to set number of columns (or rows) with facet_grid()?

The documentation on facet_grid doesn't seem to indicate that it's possible.

Thanks for the help :-)

1 Answers

You can use the ncol (or nrow) argument in facet_wrap:

ggplot(mtcars, aes(x = hp, y = mpg)) +
 geom_point()  +
 facet_wrap(~ carb, ncol = 3)

enter image description here

Related