[R] multiple plots with par mfg

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue May 23 13:48:33 CEST 2006


On Tue, 23 May 2006, Yan Wong wrote:

> Hi,
>
> I'm trying to add points to 2 plots on the fly using par(mfg=vector)
> so switch between them. However, the appropriate scales aren't
> switched when changing from one plot to another, e.g.
>
> par(mfcol=c(2,1))
> plot(1,1, col="blue")        # blue plot
> plot(1.2,1.2, col="red")     # red plot
> points(1.1,1.1)   # appears to bottom left of red point
> par(mfg=c(1,1))   # switch plots
> points(1.1,1.1)   # should appear at top of blue point, but appears
> as on red plot
> #
> > version
>          _
> platform powerpc-apple-darwin7.9.0
> arch     powerpc
> os       darwin7.9.0
> system   powerpc, darwin7.9.0
> status   Patched
> major    2
> minor    2.1
> year     2006
> month    03
> day      02
> svn rev  37488
> language R
>
>
> Is this a bug? if not, can anyone suggest a way of appending to 2
> separate plots on the fly.

No, it is user error.  par(mfg=) specifies where the next figure will the 
drawn, and points() does not draw a figure but adds to one. As the help 
page says:

      'mfg' A numerical vector of the form 'c(i, j)' where 'i' and 'j'
           indicate which figure in an array of figures is to be drawn
           next (if setting) or is being drawn (if enquiring).
           ^^^^

You need to use screen() or layout() to switch back to an existing plot.

>
> Thanks
>
> Yan Wong
> Leeds
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list