[R] setHook and lattice

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 29 19:39:55 CET 2008


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.
>
> Example code:
>
> library(lattice)
> graphics.off()
>
>
> myFunc <- function()
> {
> 	mainTitle <<- 'Page 1'
> }
>
>
> setHook('plot.new', NULL, 'replace')
> setHook('plot.new', myFunc)
>
>
> mainTitle <- 'No hook called'
> plot(1:10, main = mainTitle)
>
>
> win.graph()
> mainTitle <- 'No hook called'
> xyplot(1:10 ~ 1:10, main = mainTitle)
>
>
> setHook('plot.new', NULL, 'replace')
>
>
>
>
>> sessionInfo()
> R version 2.6.0 (2007-10-03)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods
> [7] base
>
> other attached packages:
> [1] lattice_0.16-5
>
> loaded via a namespace (and not attached):
> [1] grid_2.6.0
>
> --
> View this message in context: http://www.nabble.com/setHook-and-lattice-tp15764144p15764144.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list