bug in layout?

Paul Murrell p.murrell@auckland.ac.nz
Fri, 06 Sep 2002 13:34:18 +1200


Hi


Nicholas Lewin-Koh wrote:
> 
> Hi,
> 
>  I am not sure if this is a bug in layout or I am doing something silly.
>  If it is a bug I will file a proper report.
> 
> here goes:
> 
> plot.new()
> old.pars<-par()
> 
>  #try to divide the device into a big and small component
>  layout(matrix(c(1,2),1,2),widths=c(lcm((old.pars$pin[1]-1)*2.2),lcm(2.2)))
>  lay.pars<-par()
>  names(old.pars)[!old.pars%in%lay.pars]
>  [1] "cxy"   "fig"   "mfcol" "mfg"   "mfrow" "pin"   "plt"
>  lay.pars$pin
>  [1] -0.2828187  5.2876886
>  #Huh? should this be negative?


Because the "current plot" at this point is the second (narrower) plot
(see below), which does not actually have room for a plot (the margins
are wider than the total width allocated so the plot region is
negative).  If at this point you type "plot.new()" twice, the second
call will give an error complaining about margins being too big.


>  dev.off()
>  plot.new()
>  layout(matrix(c(1,2),1,2),widths=c(5,1))
>  lay.pars<-par()
>  lay.pars$pin
>  [1] 0.01610944 5.28768865
>  plot.new()
>  lay.pars<-par()
>  lay.pars$pin
>  [1] 4.676389 5.287689
>  Reverse of what I would have thought.


R keeps an index of which plot it is up to.  The index runs from 1 to
number-of-plots-to-appear-on-the-page.  Whenever plot.new() is called,
this index is incremented by 1 and it wraps back to 1 when it exceeds
number-of-plots-to-appear-on-the-page.

When you call layout() it sets the "current" plot region to be
number-of-plots-to-appear-on-the-page.  Note that the first thing that
must happen before any drawing can occur is a call to plot.new().  Then
when you call plot.new() it tries to go to the "next plot" which adds 1
to the "current plot" counter, which wraps back around to 1.  

I think what is causing most confusion here is the fact that the call to
layout() is setting things up ready for the next call to plot.new(),
which in turn sets everything up ready for the actual graphical output
to occur (via axes(), lines(), ...).

The short answer:  no it is not a bug :)

Hope that helps.

Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._