[R] Grid graphics issues

Chris Bergstresser chris at subtlety.com
Wed Apr 5 00:07:29 CEST 2006


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));
}




More information about the R-help mailing list