[R] divide grid.newpage into two?

Paul Murrell p.murrell at auckland.ac.nz
Tue Jul 20 02:22:31 CEST 2010


Hi

On 19/07/2010 9:17 p.m., Eleni Rapsomaniki wrote:
> Hi,
>
> Is there some easy way to split the grid.newpage() into two columns?
> For example, how could I put the two forest plots below (meta1 and
> meta2) next to each other?
>
> library(meta) data(Olkin95)
>
> meta1<- metabin(event.e, n.e, event.c, n.c,data=Olkin95,
> subset=c(41,47,51,59),sm="RR", meth="I",studlab=author) meta2=meta1
> meta2$studlab=rep("",length(meta1$studlab) ) #deleting the labels for
> the second plot
>
> grid.newpage() forest(meta1, comb.fixed=F, comb.random=F,
> rightcols="effect",leftcols="studlab") forest(meta2, comb.fixed=F,
> comb.random=TRUE, leftcols="studlab",leftlabs="")
>
> #they are superimposed... which is not what I want.
>
> Any hints/ideas much appreciated!

Try this ...

grid.newpage()
pushViewport(viewport(x=0, width=.5, just="left"))
forest(meta1, comb.fixed=F, comb.random=F,
        rightcols="effect",leftcols="studlab",
        new=FALSE)
popViewport()
pushViewport(viewport(x=.5, width=.5, just="left"))
forest(meta2, comb.fixed=F, comb.random=TRUE,
        leftcols="studlab",leftlabs="",
        new=FALSE)
popViewport()

... and NOTE the 'new=FALSE' in the calls to forest().  Depending on how 
large your final plot is, you will probably also have to play with the 
'plotwidth' and 'colgap' arguments to forest() (see ?forest.meta).

Paul

> Many thanks
>
> Eleni Rapsomaniki Research Associate Department of Public Health and
> Primary Care University of Cambridge
>
> ______________________________________________ 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 Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list