Home > front end >  Manually placing facets in facet plot ggplot
Manually placing facets in facet plot ggplot

Time:01-14

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.)?

CodePudding user response:

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

  • Related