Align ggplot2 plots vertically

Deadly 提交于 2019-11-26 17:30:30

Here's an example to align more basic grobs,

library(ggplot2)
library(grid)
library(gtable)

p <- qplot(1,1)
g <- ggplotGrob(p)

panel_id <- g$layout[g$layout$name == "panel",c("t","l")]
g <- gtable_add_cols(g, unit(1,"cm"))

g <- gtable_add_grob(g, rectGrob(gp=gpar(fill="red")),
                     t = panel_id$t, l = ncol(g))

g <- gtable_add_rows(g, unit(1,"in"), 0)
g <- gtable_add_grob(g, rectGrob(gp=gpar(fill="blue")),
                     t = 1, l = panel_id$l)

grid.newpage()
grid.draw(g)

and with your grobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!