Indexing into a gtable with gt[c(1,3), 1:2] makes sense. But the behavior for gt[c(2,1,3), c(2,1,2)] doesn't really make sense when using grobs that span rows or columns.
# Create a 3x3 gtable
gt <- gtable(name = "test",
heights=unit(c(1,1,1), "cm"), widths=unit(c(1,1,1), "cm") )
# Add some grobs
gt <- gtable_add_grob(gt, rectGrob(gp = gpar(fill="red", alpha=0.25)),
1, 1, 1, 3, clip = FALSE)
gt <- gtable_add_grob(gt, rectGrob(gp = gpar(fill="blue", alpha=0.25)),
1, 1, 3, 1, clip = FALSE)
gt <- gtable_add_grob(gt, rectGrob(gp = gpar(fill="black", alpha=0.25)),
1, 1, 3, 3, clip = FALSE)
# Draw it
grid.newpage()
grid.draw(gt)
# Drop the middle row and last col: OK
grid.newpage()
grid.draw(gt[c(1,3), 1:2])
# The following don't make sense (but they "work" in the sense that
# something is drawn)
grid.newpage()
grid.draw(gt[c(2,1,3), ])
# Doesn't make sense
grid.newpage()
grid.draw(gt[c(1,1,3), ])
grid.newpage()
grid.draw(gt[c(1,3,1), ])
grid.newpage()
grid.draw(gt[c(3,2,1), ])
Maybe it should throw a warning or error in these kinds of situations?
Indexing into a gtable with
gt[c(1,3), 1:2]
makes sense. But the behavior forgt[c(2,1,3), c(2,1,2)]
doesn't really make sense when using grobs that span rows or columns.Maybe it should throw a warning or error in these kinds of situations?