[R] direction of axes of plot

Ross Ihaka ihaka at stat.auckland.ac.nz
Mon Jun 28 11:41:28 CEST 2004


Henrik Andersson wrote:
> Assume I want to put this into a function, how do I redefine the margins 
> to fit better.
> 
> I did par(mar=c(4.1,4.1,5.1,2.1) inside the function, but then it is not 
> possible anymore to change them, I just want to change the default for 
> this plotting function, how ?

You can save the old par values and restore them
after creating your plot.

     # reset par values, saving the old ones
     oldpar = par(mar=c(4.1,4.1,5.1,2.1))

     # create stunning customized plot here

     # restore the old par values
     par(oldpar)

When embedding this in a function like yours it is better
to use the on.exit() function to restore the old values.

     f = function(...) {
         oldpar = par(mar=c(4.1,4.1,5.1,2.1))
         on.exit(par(oldpar))

         # create stunning customized plot here
     }

Error exits from the function will then also restore the old
par values.

-- 
Ross Ihaka                         Email:  ihaka at stat.auckland.ac.nz
Department of Statistics           Phone:  (64-9) 373-7599 x 85054
University of Auckland             Fax:    (64-9) 373-7018
Private Bag 92019, Auckland
New Zealand




More information about the R-help mailing list