[R] setHook and lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Mar 1 02:37:32 CET 2008


On 2/29/08, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> See share/perl/massage-examples.pl
>
>  Hint: lattice is a (very sophisticated) wrapper for grid, and it is
>  grid.newpage() that has the hook.
>
>  Hint 2: look at the version in the R-devel sources,
>
>  https://svn.r-project.org/R/trunk/share/perl/massage-Examples.pl
>
>  for use with lattice.
>
>
>  On Fri, 29 Feb 2008, Jim Price wrote:
>
>  >
>  > Hi,
>  >
>  > I am trying to find a way to automate production of page numbers in plots
>  > produced using the lattice package. To do this, I started playing around
>  > with setHook which works fine with vanilla plot, but the hook 'plot.new'
>  > doesn't appear to be relevant to the lattice package. I was wondering if
>  > there is a alternative someone can suggest for use with the lattice package.

Another solution is to use the 'page' argument. It takes its default from
lattice.getOption("default.args")$page, so you could set something like

lattice.options(default.args = list(page = function(n) {
    panel.text(lab = sprintf("Page %d", n), x = 0.95, y = 0.05)
}))

This would put page numbers starting from 1 for each plot, but you
could easily use a global counter instead.

-Deepayan



More information about the R-help mailing list