[R] multiple plots in single frame: 2 upper, 1 lower

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Jul 21 12:34:29 CEST 2011


On Wed, 2011-07-20 at 23:38 +1200, Rolf Turner wrote:
> On 20/07/11 11:07, DrCJones wrote:
> > Hi,
> >
> > par(mfrow = c(2,2))
> >
> > will create a 2x2 window that I can use to plot 4 diferent figures in:
> > [plot1 plot2]
> > [plot3 plot4]
> >
> > But how can do 3 so that the bottom spans the width of the upper two:
> >
> > [plot1 plot1]
> > [p   l  o  t 3]
> >
> > Is this possible in R?
> 
> In R ***anything*** is possible. :-)
> 
> Your requirement is no only possible, but easy!
> 
> See ?layout
> 
> You may have to expend a bit of effort to understand the syntax, but
> that will be good for your karma. :-) 

It may help the OP to think of the layout as a 2*2 matrix:

1 2
3 4

say, with plot 3 using regions 3 and 4. If we fill the same matrix with
the plot number we want to draw in it, we have

1 2
3 3

>From there it is easy to specify the layout by directly building that
matrix in R:

> (m <- matrix(c(1:3,3), ncol = 2, byrow = TRUE))
     [,1] [,2]
[1,]    1    2
[2,]    3    3

and pass that to `layout()`

layout(m)
## invisible() just to stop replicate returning something visible
invisible(replicate(3, plot(1:10))) 
layout(1)

HTH

G

>  It ***will*** do exactly what you
> want, if you ask it nicely.
> 
>      cheers,
> 
>          Rolf Turner
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list