I am using facet_grid to co-visualize data according to two factors. One factor as too many levels to fit in one row. I would therefore like to achieve something like facet_wrap, but with 2 dimensions:
- Can facet_wrap be used with two factors?
- Can facet_grid be used to wrap over one factor?
The output should look something like
A B C
. . . 1
. . . 2
D E
. . 1
. . 2
Factor 1 as 5 levels A-E, wrapped on 2 rows, and Factor 2 as two levels 1-2, repeated on each row.
Here is a practical example to play with:
library(ggplot2)
df <- data.frame(y=rnorm(1000), f1=rep(1:10, 100), f2=rep(1:2, each=500))
ggplot(df, aes(x=x)) + geom_histogram() + facet_grid(f2~f1)
I would like to split the image in two, with the five first levels on top, and the last five under, while maintaining the 1 and 2 rows for each.
Many thanks for your consideration!