[R] unexpected par('pin') behaviour

Martin Maechler maechler at stat.math.ethz.ch
Thu Jul 14 12:34:41 CEST 2005


>>>>> "joerg" == joerg van den hoff <j.van_den_hoff at fz-rossendorf.de>
>>>>>     on Wed, 13 Jul 2005 16:00:58 +0200 writes:

    joerg> hi everybody,
    joerg> I noticed the following: in one of my scripts 'layout' is used to 
    joerg> generate a (approx. square) grid of variable dimensions (depending on 
    joerg> no. of input files). if the no. of subplots (grid cells) becomes 
    joerg> moderately large  (say > 9) I use a construct like

    joerg>   ###layout grid computation and set up occurs here###
    joerg>   ...
    joerg>   opar <- par(no.readonly = T);
    joerg>   on.exit(par(opar))
    joerg>   par(mar=c(4.1, 4.1, 1.1, .1))
    joerg>   ###plotting occurs here####
    joerg>   ...

    joerg> to reduce the figure margins to achieve a more
    joerg> compact display. apart from 'mar' no other par()
    joerg> setting is modified.

yet another example of using  par('no.readonly') when it's not
needed and inefficient.

Replacing the above by

    ###layout grid computation and set up occurs here###    
    ...
     op <- par(mar=c(4.1, 4.1, 1.1, .1))
     on.exit(par(op))
    ###plotting occurs here####

will be much more efficient and even solve your problem with "pin".

But then, yes, there might be another par() problem hidden in
your code / example, 
but unfortunately you have not specified reproducible code.


    joerg> this works fine until the total number of subplots becomes too large 
    joerg> ("large" depending on the current size of the X11() graphics device 
    joerg> window, e.g. 7 x 6 subplots for the default size fo x11()).

    joerg> I then get the error message (only _after_ all plots are correctly 
    joerg> displayed, i.e. obviously during execution of the above on.exit() call)

    joerg> Error in par(opar) :
    joerg> invalid value specified for graphics parameter "pin"

    joerg> and par("pin") yields:

    joerg> [1]  0.34864 -0.21419

you mean *after* all the plotting ,  not the "pin" values in
'opar', right?

    joerg> which indeed is invalid (negative 2nd component).

    joerg> I'm aware of this note from ?par:

    joerg> The effect of restoring all the (settable) graphics parameters as
    joerg> in the examples is hard to predict if the device has been resized.
    joerg> Several of them are attempting to set the same things in different
    joerg> ways, and those last in the alphabet will win.  In particular, the
    joerg> settings of 'mai', 'mar', 'pin', 'plt' and 'pty' interact, as do
    joerg> the outer margin settings, the figure layout and figure region
    joerg> size.

{{which shows you the known  but not widely known fact that
  traditional par() based graphics are ``flawed by design''
  and that's why there is the package "grid" for better 
  designed graphics
}}

    joerg> but my problem occurs without any resizing of the
    joerg> x11() window prior to resetting par to par(opar).

It still would be interesting to get a reproducible example
here, as the posting guide asks for.

Martin


    joerg> any ideas, what is going on?

    joerg> platform powerpc-apple-darwin7.9.0
    joerg> arch     powerpc
    joerg> os       darwin7.9.0
    joerg> system   powerpc, darwin7.9.0
    joerg> status   Patched
		    ^^^^^^^
I hope that this is not the basic problem 

    joerg> major    2
    joerg> minor    1.0
    joerg> year     2005
    joerg> month    05
    joerg> day      12
    joerg> language R

    joerg> regards,

    joerg> joerg




More information about the R-help mailing list