Experiments with grid.draw

library(grid)
one <- unit(1, "cm")

# rectGrob with no fill
grob1 <- rectGrob(width = one, height = one)

# gTree of recGrob, with blue fill
test <- gTree(children = gList(grob1), cl = "test", gp = gpar(fill = "blue"))

# draw rectGrob: No fill
grid.newpage()
grid.draw(grob1)

plot of chunk unnamed-chunk-1


# draw gTree: Blue fill
grid.newpage()
grid.draw(test)

plot of chunk unnamed-chunk-1



# Paul Murrell's code: This essentially calls grid.draw drawing each child
# in the gTree Has the same effect as the first plot (and ignores the gp
# in the gTree, I think)
grid.draw.test <- function(x, ...) {
    lapply(x$children, grid.draw)
}
grid.newpage()
# NO blue fill
grid.draw(test)

plot of chunk unnamed-chunk-1

## $GRID.rect.1
## NULL
## 

widthDetails() and grobWidth()

Here's what happens when you call widthDetails() and grobWidth() on the rectGrob and gTree objects:.

# widthDetails of rectGrob
widthDetails(grob1)
## [1] 0.393700787401575inches
convertUnit(widthDetails(grob1), "cm")
## [1] 0.999999999999999cm

# grobWidth of gTree
grobWidth(grob1)
## [1] 1grobwidth
convertUnit(grobWidth(grob1), "cm")
## [1] 0.999999999999999cm


# widthDetails of gTree
widthDetails(test)
## [1] 1null
convertUnit(widthDetails(test), "cm")
## [1] 0cm

# grobWidth of gTree
grobWidth(test)
## [1] 1grobwidth
convertUnit(grobWidth(test), "cm")
## [1] 0cm