The following code produces 6 plots on a page, but the first is distorted and different from the others: par(mfrow=c(3,2), las=2) for (i in 1:6) { frame() par(mar=c(7, 7, 1, 1)) axis(2); box(); abline(h=seq(0,1,.5), col=2:4) } The first plot's axes are mis-aligned with the plotting area implied by the box. It seems to be a result of calling par(mar) after frame(). Is this expected behavior, or some kind of bug? I'm using R-2.1.0 on Linux with X11; I see the same behavior in Windows. -- David Brahm (brahm at alum.mit.edu)
Brahm, David wrote:> The following code produces 6 plots on a page, but the first is > distorted and different from the others: > > par(mfrow=c(3,2), las=2) > for (i in 1:6) { > frame() > par(mar=c(7, 7, 1, 1)) > axis(2); box(); abline(h=seq(0,1,.5), col=2:4) > } > > The first plot's axes are mis-aligned with the plotting area implied > by the box. It seems to be a result of calling par(mar) after frame(). > Is this expected behavior, or some kind of bug?Yes expected, at first yiou generate the plot, then you change the margins, and then you add stuff (axis). For the second plot, par(mar) has already been called in the first iteration. Why do you want to use it inside the loop? Uwe Ligges> I'm using R-2.1.0 on Linux with X11; I see the same behavior in Windows. > > -- David Brahm (brahm at alum.mit.edu) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
I wrote:> par(mfrow=c(3,2), las=2) > for (i in 1:6) { > frame() > par(mar=c(7, 7, 1, 1)) > axis(2); box(); abline(h=seq(0,1,.5), col=2:4) > } > The first plot's axes are mis-aligned with the plotting area...Uwe Ligges <ligges at statistik.uni-dortmund.de> replied:> Yes expected, at first you generate the plot, then you change the > margins, and then you add stuff (axis)... > Why do you want to use it inside the loop?Thanks, Uwe, for making it clearer. My toy example puts these commands inside a loop because my real-life problem has them inside a function, which is called inside a loop. My function sets par(mar, usr, mgp). It seems I need to set par(mar) before frame(), par(usr) after frame(), and par(mgp) either before or after. I was not thinking of frame() as "generating the plot" so much as "moving to the next location", so I didn't understand why the order mattered. Thanks again! -- David Brahm (brahm at alum.mit.edu)