Keep or set the ratio between text labels and size of plot in grid.arrange

后端 未结 2 1832
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 10:33

I am trying to arrange 2 plots created using ggplot2 and would like the plots to be the size of a square and one next to the other, with the common legend next

2条回答
  •  [愿得一人]
    2021-01-14 11:15

    I'm not sure what you expect for the output, but try this,

    g = arrangeGrob(
      arrangeGrob(p1 + coord_fixed() + theme(legend.position="none"),
                  p2 + coord_fixed() +theme(legend.position="none"),
                  main = textGrob("The main figure title is also small and hard to align left",  x=0, hjust =0, vjust=1, gp = gpar(fontsize = 22)), nrow=1), 
                 mylegend, widths=unit.c(unit(1, "npc") - sum(mylegend$width), 
                                         sum(mylegend$width)), nrow=1)
    
    ggsave("layout.pdf", g, width=12, height=5)
    

提交回复
热议问题