13

I can create a faceted plot like so, with 3 plots stacked vertically:

ggplot(iris, aes(Petal.Length)) + stat_bin() + facet_grid(Species ~ .)

Is it possible to move the labels to the top of each graph, like they would be if I'd done horizontal stacking with facet_grid(. ~ Species)?

The reason I want this is that my plots are long time series plots, so I want the full width for each one, but the labels (which essentially function as titles to explain the facets) for each plot are too long to fit in the small label area at the right of the plot.

joran
  • 169,992
  • 32
  • 429
  • 468
Ken Williams
  • 22,756
  • 10
  • 85
  • 147

2 Answers2

14

Yes. Use facet_wrap instead of facet_grid and be sure to also specify the argument ncol=1:

ggplot(iris, aes(Petal.Length)) + stat_bin() + facet_wrap(~Species, ncol=1)

enter image description here

Andrie
  • 176,377
  • 47
  • 447
  • 496
  • The y axis has here a max of 25 each time. Any was to actually have the original behavior of having the axis set to the proper range per facet? – Gildas Mar 06 '19 at 12:23
  • add `facet_wrap(~Species, ncol=1,scales="free_y")` – baibo Feb 08 '21 at 11:27
4

Try this:

ggplot(iris, aes(Petal.Length)) + stat_bin() + facet_wrap(~Species,nrow = 3)

enter image description here

joran
  • 169,992
  • 32
  • 429
  • 468