Re: [R] unexpected par('pin') behaviour

From: joerg van den hoff <>
Date: Fri 15 Jul 2005 - 01:19:51 EST

Martin Maechler wrote:

>>>>>>"joerg" == joerg van den hoff <>
>>>>>>    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.

might be. but at least it is immune against modifying some more 'par' settings in the course of modfications at some other place in the programm. inefficiency: should be at the ppm level of total cpu-usage in my case, :-). what's so bad with copying back and forth this moderately large vector?
> 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".
right (solves the problem). I'll adopt this change for the time being. thank you.

> 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

... which seems to my simple mind a lot more complicated to come to terms with than the graphics package. I understand that grid is more powerful but the subset of functionality provided by 'graphics' seems more difficult to use in 'grid'. wrong or right?
> }}
> 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.


f <- function(n=7, m=6) {

    nm <- n*m

    opar <- par(no.readonly = T)
    par(mar = c(4.1, 4.1, 1.1, 0.1))

    for (i in 1:nm) plot(i, pch=(i-1)%%25+1)     layout(1)
f(5) #good
f() #bad (at least for x11() default size) par('pin')

> Martin

thanks for bothering.
> 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
no, don't think so. that concerned the MacOS GUI, I believe.
> joerg> major 2
> joerg> minor 1.0
> joerg> year 2005
> joerg> month 05
> joerg> day 12
> joerg> language R
> joerg> regards,
> joerg> joerg
> mailing list PLEASE do read the posting guide! Received on Fri Jul 15 01:26:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:40 EST