Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

ggplot2

facets

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.

like image 454
Ken Williams Avatar asked Feb 20 '12 19:02

Ken Williams


1 Answers

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

like image 184
Andrie Avatar answered Sep 21 '22 08:09

Andrie