From ggrothendieck at gmail.com  Wed Dec 26 19:09:50 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 26 Dec 2007 13:09:50 -0500
Subject: [Rd] Predictable grid names
Message-ID: <971536df0712261009n70ae1449n70e24040c33f7794@mail.gmail.com>

One thing that makes modifying lattice grid objects difficult is that if
you create the same plot twice you get different grid names for
some grid objects:

1. I wonder if there is some possibility in grid to reset the
names after a grid.newpage(), say, so that one can get predictable
names or some other strategy for getting predictable names.
Sort of like a set.seed() for grid except this has nothing to do with
random numbers.

2. grid.ls() is a great improvement over what previously existed but another
thing that would be nice would be to be able to list out more info with
the grid object so one can more easily identify it.  Sort of like ls -l.
And/or maybe a where clause restricting which objects are listed, e.g. just
list grid objects that are dark green.  I have been using the
following to show the
color values (which displays them if they are in the gp list but not
otherwise) but it would be nice to have something more general and
built in.  Or perhaps something already exists that I am not aware of.

library(lattice)
library(grid)
# show tree with names and col values
recurse <- function(x, indent = "") {
  if (!is.null(x$name)) {
	cat(indent, x$name)
	if (!is.null(x$gp)) cat(" col:", x$gp$col)
	cat("\n")
  }
  for (ch in x$children) Recall(ch, indent = paste(indent, "."))
}
xyplot(Sepal.Length ~ Sepal.Width, iris, group = Species, col = 11:13,
  auto.key = TRUE)
gg <- grid.grab()
recurse(gg)



[Rd] Predictable grid names
Gabor Grothendieck