Re: [R] gridBase Base Plot Positioning

From: Paul Murrell <p.murrell_at_auckland.ac.nz>
Date: Fri, 29 Apr 2011 08:09:52 +1200

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/

______________________________________________
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.
Received on Thu 28 Apr 2011 - 20:11:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Apr 2011 - 20:20:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive