bug in layout?

Nicholas Lewin-Koh nikko@hailmail.net
09 Sep 2002 12:00:37 +0800


Hi,
I think I am beginning to understand how this works, but obviously not
fully. layout changes the following pars
[1] "cxy"  "fig"  "fin"  "mfg"  "pin"  "plt"  "usr"  "xaxp" "yaxp"

and as you state below moves the counter to N so after layout is called
if par is called one gets the pars for the Nth plot. Now after a call to
plot.new() the counter is set to 1 and a call to par gets the pars() for
the current plot.

what if I have a call to layout in a function, and i want to alter the
parameter "pin" in the first plot? Advancing through using plot.new()
does not seem to work because pin gets set each time the frame advances.

Any ideas?

Thanks
Nicholas

On Fri, 2002-09-06 at 09:34, Paul Murrell wrote:
> 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._