a_todd12
a_todd12

Reputation: 550

Manually placing facets in facet plot ggplot

If, for example, you have 7 panels and you specify facet_wrap(~model, nrow = 3) ggplot will default to a 3x3x1 layout. Is it possible to get ggplot to do 3x2x2 (or 2x2x3, etc.)?

Upvotes: 1

Views: 83

Answers (1)

Maël
Maël

Reputation: 51974

You can use ggh4x to specify the design of your facet:

library(ggh4x)
design = matrix(c(1, 1, 2, 2, 3, 3, 
                  4, 4, 4, 5, 5, 5, 
                  6, 6, 6, 7, 7, 7), 
                3, 6, byrow = TRUE)
ggplot(mpg, aes(displ, hwy, colour = as.factor(cyl))) + 
  geom_point() +
  facet_manual(vars(class), design = design)

enter image description here

Upvotes: 5

Related Questions