问题
Why does the following plot not display the numbers (g
; specified via textGrob(label=g))
) in the 6 panels? If I use the text grob only, this also works, but a text grob and a rectangular grob seem to be not so easy. Unfortunately the help page of gtable_add_grob
does not give a lot of help...
require(gtable)
base <- gtable(widths=unit(rep(1, 2), "null"),
heights=unit(rep(1, 3), "null"))
g <- 1
for(i in 1:3) {
for(j in 1:2) {
base <- gtable_add_grob(base, list(rectGrob(gp=gpar(fill="#FF000088")), textGrob(label=g)), i, j)
g <- g+1
}
}
grid.draw(base)
回答1:
The grobs need different names:
base <- gtable_add_grob(base,
list(rectGrob(gp=gpar(fill="#FF000088")), textGrob(label=g)), i, j,
name=1:2)
来源:https://stackoverflow.com/questions/18028920/how-to-use-gtable-add-grob-does-not-add