Multiple ggplots of different sizes

后端 未结 5 1694
醉酒成梦
醉酒成梦 2020-12-02 12:35

It\'s relatively simple using grid.arrange in the gridExtra package to arrange multiple plots in a matrix, but how can you arrange plots (the ones

5条回答
  •  北海茫月
    2020-12-02 13:11

    An alternative with gtable

    library(gtable)
    
    gl <- lapply(1:9, function(ii) grobTree(textGrob(ii), rectGrob()))
    # gl <- lapply(1:9, function(ii) ggplotGrob(qplot(1,1) + ggtitle(ii)))
    
    gt <- gtable(widths=unit(rep(1,5), "null"),
                 heights=unit(rep(1,3), "null"))
    
    gtable_add_grobs <- gtable_add_grob # alias
    
    gt <- gtable_add_grobs(gt, gl, 
                           l=c(1,4,5,4,5,1,2,3,4),
                           r=c(3,4,5,4,5,1,2,3,5),
                           t=c(1,1,1,2,2,3,3,3,3),
                           b=c(2,1,1,2,2,3,3,3,3))
    grid.newpage()
    grid.draw(gt)
    

    enter image description here

提交回复
热议问题