Created
February 26, 2012 08:42
-
-
Save baptiste/1915307 to your computer and use it in GitHub Desktop.
alignment of gtables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gtable) | |
gcore <- gtable_matrix(name="core", | |
grobs=matrix(list(rectGrob(gp=gpar(fill="blue",alpha=0.5))),1,1), | |
widths=unit(5,"cm"), heights=unit(3,"cm")) | |
gtop <- gtable_matrix(name="top", | |
grobs=matrix(list(rectGrob(gp=gpar(fill="red",alpha=0.5))),1,1), | |
widths=unit(5,"cm"), heights=unit(1,"cm")) | |
gleft <- gtable_matrix(name="left", | |
grobs=matrix(list(rectGrob(gp=gpar(fill="green",alpha=0.5))),1,1), | |
widths=unit(1,"cm"), heights=unit(3,"cm")) | |
align_table <- function(core, top, left, just=c("center", "center")){ | |
gl <- grid.layout(nrow=2,ncol=2, | |
widths=unit.c(sum(left$widths), sum(core$widths)), | |
heights=unit.c(sum(top$heights), sum(core$heights)), | |
just=just) | |
g1 <- gtable_gTree(core, vp=viewport(layout.pos.row=2, layout.pos.col=2)) | |
g2 <- gtable_gTree(top, vp=viewport(layout.pos.row=1, layout.pos.col=2)) | |
g3 <- gtable_gTree(left, vp=viewport(layout.pos.row=2, layout.pos.col=1)) | |
gTree(children=gList(g1,g2,g3), vp=viewport(layout=gl)) | |
} | |
grid.newpage() | |
g <- align_table(gcore,gtop,gleft) | |
grid.draw(g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment