How can I align multiple plots by their titles instead of plot area?

后端 未结 2 905
北恋
北恋 2021-01-14 04:09

I\'m using egg to align multiple plots on a page. I\'m wondering if it\'s possible to align two columns by the titles a) and c) instead of plot are

相关标签:
2条回答
  • 2021-01-14 04:46

    Adding a blank dummy faceting variable to plot p1/ a) seems like the easiest solution

    p1 <- ggplot(data.frame(mtcars, dummy=''), 
                 aes(mpg, wt, colour = factor(cyl))) +
      geom_point() + ggtitle("a)") +
      facet_wrap(~dummy)
    

    0 讨论(0)
  • 2021-01-14 05:04

    I found another way by using cowplot package

    left_col <- cowplot::plot_grid(p1 + ggtitle(""), p2 + ggtitle(""), 
                                   labels = c('a)', 'b)'), label_size = 14,
                                   ncol = 1, align = 'v', axis = 'lr') 
    cowplot::plot_grid(left_col, p3 + ggtitle(""), 
                       labels = c('', 'c)'), label_size = 14,
                       align = 'h', axis = 'b')
    

    See also here

    Edit:

    A recently developed package patchwork for ggplot2 can also get the job done

    library(patchwork)
    
    {
      p1 + {p2} + patchwork::plot_layout(ncol = 1)
    } / p3 + patchwork::plot_layout(ncol = 2)
    

    0 讨论(0)
提交回复
热议问题