[R] Grid graphics issues

Paul Murrell p.murrell at auckland.ac.nz
Wed Apr 5 00:33:54 CEST 2006


Hi


Chris Bergstresser wrote:
> Hi all --
> 
>     So I'm trying to use lattice graphics, but I want to use a
> sunflower plot, which doesn't seem to be part of lattice.  No problem,
> I put together the following code, which mostly works -- *except* for
> the first graph it generates.  If it opens the graphic device, then it
> draws the xygrid, clears the device, then draws the sunflowerplot. 
> All subsequent output operations work fine, as does rerunning the code
> with the graphic device open.
>    What's going on?  How can I fix this?  I tried looking through the
> family of dev.* to no success.  I can use trellis.device to open the
> device, but that causes the same problem.
> 
> -- Chris
> 
> library("grid");
> library("lattice");
> library("gridBase");
> 
> trellis.par.set(theme = col.whitebg());
> outer.plot.limits = c(0.75, 5.25);
> inner.plot.limits = c(0.92, 5.08);
> sunpanel <- function(x, y, subscripts, ...) {
> 	pushViewport(viewport(x = 0.5, y = 0.5, just = "center"));
> 	par(plt = gridPLT(), new = TRUE);
> 	sunflowerplot(x, y, axes = FALSE, xlab = "", ylab = "",
>                   xlim = inner.plot.limits, ylim = inner.plot.limits);
> 	popViewport(1);
> }
> 
> for (i in 1:10) {
> 	x = round(runif(100, 1, 5));
> 	y = round(runif(100, 1, 5));
> 	print(xyplot(y ~ x, xlim = outer.plot.limits, ylim = outer.plot.limits,
>                      main = i, aspect = "iso", between = list(x = 1, y = 0),
>                      panel = sunpanel));
> }


Try this modification ...

for (i in 1:10) {
	x = round(runif(100, 1, 5));
	y = round(runif(100, 1, 5));
	# CHANGE !!!!
	# Start a traditional graphics page
	plot.new()
	print(xyplot(y ~ x,
                      xlim = outer.plot.limits, ylim = outer.plot.limits,
                      main = i, aspect = "iso",
                      between = list(x = 1, y = 0),
                      panel = sunpanel));
}

This should make the first page work AND remove the warning about 
"calling par(new=) with no plot".

Paul
-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list