Align edges of ggplot choropleth (legend title varies)

前端 未结 2 1113
南笙
南笙 2020-12-14 12:11

I am attempting to align the left and right edges of 4 ggplot choropleth maps using this method. I am unable to do this though.

Original plot:

相关标签:
2条回答
  • 2020-12-14 12:45

    Here is an example:

    library(gtable)
    grid.draw(cbind(rbind(p1, p2, size="last"), rbind(p3, p4, size="last"), size = "first"))
    

    enter image description here


    Updated

    This is a bad hack so I don't recommend to use. Probably this will not work in future.

    gt <- cbind(rbind(p1, p2, size="last"), rbind(p3, p4, size="last"), size = "first")
    for (i in which(gt$layout$name == "guide-box")) {
      gt$grobs[[i]] <- gt$grobs[[i]]$grobs[[1]]
    }
    grid.draw(gt)
    

    enter image description here

    0 讨论(0)
  • 2020-12-14 12:45

    Using cowplot package:

    library(cowplot)
    plot_grid(plot1, plot3, plot2, plot4, ncol = 2, align = "v")
    

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