hadley/gtable — pull request #35 by wch (2012-09-08 05:33:26+00:00)
Title: Fixes to print order

`print.gtable`: print z order but don't sort names by z order

Previously, the layout names were sorted by z order, but the grobs weren't. This resulted in a mismatch between the names and the grobs. It's better to not sort by z by default, since that doesn't match how indexing works. The new `zsort` option allows the output to be sorted by z.

Old output:

```
p <- qplot(1:3, 1:3, colour=1:3)
g <- ggplotGrob(p)

# Print out the table
# Note there's a bug in the ordering of the names. They're sorted by the
# z order, but they shouldn't be. This is fixed in the devel version of
# gtable.
g
# TableGrob (6 x 6) "layout": 9 grobs
# (1-6,1-6) background: rect[plot.background.rect.105]
# (4-4,3-3) spacer: absoluteGrob[GRID.absoluteGrob.89]
# (3-3,4-4) panel: zeroGrob[NULL]
# (3-3,3-3) axis-l: gTree[GRID.gTree.77]
# (4-4,4-4) axis-b: absoluteGrob[GRID.absoluteGrob.83]
# (5-5,4-4) xlab: text[axis.title.x.text.91]
# (3-3,2-2) ylab: text[axis.title.y.text.93]
# (3-3,5-5) guide-box: gtable[guide-box]
# (2-2,4-4) title: text[plot.title.text.103]
```

New output:

```
g
# TableGrob (6 x 6) "layout": 9 grobs
# z cells name grob
# 1 0 (1-6,1-6) background rect[plot.background.rect.44]
# 2 3 (3-3,3-3) axis-l absoluteGrob[GRID.absoluteGrob.28]
# 3 1 (4-4,3-3) spacer zeroGrob[NULL]
# 4 2 (3-3,4-4) panel gTree[GRID.gTree.16]
# 5 4 (4-4,4-4) axis-b absoluteGrob[GRID.absoluteGrob.22]
# 6 5 (5-5,4-4) xlab text[axis.title.x.text.30]
# 7 6 (3-3,2-2) ylab text[axis.title.y.text.32]
# 8 7 (3-3,5-5) guide-box gtable[guide-box]
# 9 8 (2-2,4-4) title text[plot.title.text.42]

print(g, zsort=TRUE)
# TableGrob (6 x 6) "layout": 9 grobs
# z cells name grob
# 1 0 (1-6,1-6) background rect[plot.background.rect.44]
# 3 1 (4-4,3-3) spacer zeroGrob[NULL]
# 4 2 (3-3,4-4) panel gTree[GRID.gTree.16]
# 2 3 (3-3,3-3) axis-l absoluteGrob[GRID.absoluteGrob.28]
# 5 4 (4-4,4-4) axis-b absoluteGrob[GRID.absoluteGrob.22]
# 6 5 (5-5,4-4) xlab text[axis.title.x.text.30]
# 7 6 (3-3,2-2) ylab text[axis.title.y.text.32]
# 8 7 (3-3,5-5) guide-box gtable[guide-box]
# 9 8 (2-2,4-4) title text[plot.title.text.42]
```

I'm not sure I got the documentation right, since there's a new parameter with an S3 method.