[R] gridBase Base Plot Positioning

Paul Murrell p.murrell at auckland.ac.nz
Thu Apr 28 22:09:52 CEST 2011


Hi

On 28/04/2011 3:00 p.m., Dario Strbenac wrote:
> Hello,
>
> I'm trying to follow the documentation of how to use gridBase, and
> I've reached the minimal code example below as my best effort. Can
> someone explain how to keep the column of boxplots on the same page
> as the rectangles (even though I've tried new = TRUE) ? Also, would
> it be hard / possible to match up the middle of each boxplot to the
> middle of each rectangle ?

The call to plot.new() is starting a new page (and wiping all of the 
previous 'grid' drawing.  If you put the grid.newpage() call first, 
things look better.  Something like this ...

plot.new()
pushViewport(plotViewport(c(5, 5, 4, 2)))
pushViewport(viewport(layout = grid.layout(4, 6)))
for(i in 1:5)
{
     for(i2 in 1:4)
     {
         pushViewport(viewport(layout.pos.row = i2, layout.pos.col = i))
         grid.rect()
         popViewport()
     }
}
pushViewport(viewport(layout.pos.col = 6))
par(plt = gridPLT(), new = TRUE)
randData <- lapply(1:4, function(x) sample(10, 10, TRUE))
boxplot(randData, horizontal = TRUE)

Paul

> pdf("tmp.pdf", h = 6, w = 10) pushViewport(plotViewport(c(5, 5, 4,
> 2))) pushViewport(viewport(layout = grid.layout(4, 6))) for(i in
> 1:5) { for(i2 in 1:4) { pushViewport(viewport(layout.pos.row = i2,
> layout.pos.col = i)) grid.rect() popViewport() } }
> pushViewport(viewport(layout.pos.col = 6)) plot.new() par(plt =
> gridPLT(), new = TRUE) randData<- lapply(1:4, function(x) sample(10,
> 10, TRUE)) boxplot(randData, horizontal = TRUE) dev.off()
>
> I'm using gridBase_0.4-3.
>
> Thanks, Dario.
>
> -------------------------------------- Dario Strbenac Research
> Assistant Cancer Epigenetics Garvan Institute of Medical Research
> Darlinghurst NSW 2010 Australia
>
> ______________________________________________ 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