Ken Williams
Ken Williams

Reputation: 23995

How can I move facet labels to top of my graph?

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.

Upvotes: 13

Views: 5877

Answers (2)

Andrie
Andrie

Reputation: 179468

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

Upvotes: 14

joran
joran

Reputation: 173627

Try this:

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

enter image description here

Upvotes: 4

Related Questions