[R] Handling of par() with variables

Joris Meys jorismeys at gmail.com
Fri Jun 4 12:34:38 CEST 2010


I think you misunderstand the working of par(). If you set new
parameters, R allows you to store the old parameters simultaneously.

Take a look at :

par(no.readonly=T)
oldpar <- par(mar=c(1,1,1,1),tck=0.02)
par(no.readonly=T)
par(oldpar)
par(no.readonly=T)

So your line :
newpar <- par(mar=c(3.1,3.1,0.1,0.1),  # margin for figure area
            oma=c(0,0,0,0),          # margin for outer figure area
            cex.axis=0.9,          # font size axis
            mgp=c(2,0.6,0),          # distance of axis
            tck=0.02                # major ticks inside
            )
actually stores the OLD parameters in newpar, and not the new ones. If
you want to set them using a variable, you'll need something like :
newmar <- c(3.1,3.1,1.0,1.0) # store the mar values in a variable
oldpar <- par(mar=newmar) # set the mar and store the old values
...
par(oldpar) # back to the old parameters

Cheers
Joris
On Fri, Jun 4, 2010 at 11:40 AM, Steffen Uhlig
<steffen.uhlig at htw-saarland.de> wrote:
> Hello!
>
> In order to plot multiple graphs with the same setup I use the
> following code-structure:
>
> ###########################################################
> # storing old parameter set
> oldpar <- par(no.readonly=T)t
>
> #copying old parameter set
> newpar <- par(no.readonly=T)
>
> #adjusting parameters
> newpar <- par(mar=c(3.1,3.1,0.1,0.1),  # margin for figure area
>             oma=c(0,0,0,0),          # margin for outer figure area
>             cex.axis=0.9,          # font size axis
>             mgp=c(2,0.6,0),          # distance of axis
>             tck=0.02                # major ticks inside
>             )
>
> ...
> ...
> postscript(...)
> par(newpar)
> ...
> dev.off()
> ###########################################################
>
> Calling the variable newpar delivers the old paramter set only (from
> code-line "newpar <- par(no.readonly=T)"). If the code-segment "newpar
> <- par(mar=..." runs a second time, the correct paramter set is
> stored, however, just the 5 parameters adjusted and not the full list.
>
> My question is, why must the code segment "newpar<-par(mar...)" run
> twice? Is there a better way to handle the graphics output? I would be
> grateful for a pointer on a FAQ-section or to an older discussion
> thread in this group!
>
> Thank you very much in advance!
>
> Regards,
> /steffen
>
> --
> Steffen Uhlig, PhD
> Mechatronik und Sensortechnik
> HTW des Saarlandes
> Goebenstraße 40
> 66117 Saarbrücken
>
> Tel.: +49 (0) 681 58 67 274
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-help mailing list