[R] Graphics: calling par(mar) after frame()

Brahm, David David.Brahm at geodecapital.com
Wed Jul 6 23:49:19 CEST 2005


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)




More information about the R-help mailing list