r-lib/gtable

stacking two gtables

Closed this issue · 0 comments

A function to combine two isomorphic tables with a given z-order, e.g. adding a background layer below an existing gtable. Here's a basic draft,

gtable_stack <- function(g1, g2, zorder = "first"){
  g1$grobs <- c(g1$grobs, g2$grobs)
  g2$layout <- transform(g2$layout, z= g1$layout$z - 1, name="g2")
  g1$layout <- rbind(g1$layout, g2$layout)
  g1
}