Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading