Skip to content
Prev 26533 / 63424 Next

pairs, par

I dug around in pairs, and I think it has something to do with the
on.exit(par(opar)) bit:

f <- function() {
	opar <- par(mfrow = c(2, 2), mar = rep(0.5, 4), oma = rep(4, 4))
	on.exit(par(opar))
	for(i in 1:4) plot(0:1, 0:1)
	par(c("mfg", "omd", "fig", "plt", "usr"))
	print(opar)
}
f()
par(xpd = NA)
par(c("omd", "fig", "plt", "usr"))
points(0 - 0.01 * 1:100, 0 - 0.01 * 1:100)
points(0 - 0.01 * 1:100, 1 + 0.01 * 1:100)
points(1 + 0.01 * 1:100, 0 - 0.01 * 1:100)
points(1 + 0.01 * 1:100, 1 + 0.01 * 1:100)

My guess is that there are 2 sets of graphical parameters, the ones
stored in par and the ones used by the plotting functions.  Before
par(opar) gets called, the two are synchronized.  When par(opar) gets
called, we somehow set new values for par without changing the ones
used by the plotting functions, and the data used by points becomes
out of sync with the par information.

This is reflected in this much simpler example:

x11()
par(c("omd", "fig", "plt", "usr"))
points(0, 0)

Again, par is defined, but this time the data used by the plotting
functions has not been set, and an error occurs.

Thanks for the workaround suggestion.  I guess I can always define a
new plotting region to force par and the plotting data to
re-synchronize.  It might be nice if those two didn't go out of sync,
as I had assumed par would always be reliable.

Oliver
On 10/29/07, Tony Plate <tplate at acm.org> wrote: