Search code examples
rggplot2graphfacetfacet-wrap

Setting the last plot in the middle with facet_wrap


I am trying to create some multiplots with facet_wrap. However I am not sure if is the right approach for my graph. Here is a short reproducible example:

 ggplot(airquality, aes(x = Day, y = Temp)) +
  facet_wrap(~Month) + 
  geom_line()

This produces this plot here:

enter image description here

Is it possible to "center" the two plots in the 2nd row with the facet_wrap approach ?

Note, that I don't want to reorder the plots, I just want to Center the 2nd row


Solution

  • @Tjebo's suggestion of using cowplot will work:

    p <- ggplot(mapping = aes(x = Day, y = Temp)) +
      facet_wrap(~Month) + 
      geom_line()
    
    cowplot::plot_grid(
      p %+% subset(airquality, Month < 8),
      p %+% subset(airquality, Month > 7),
      nrow = 2
    )
    

    enter image description here