[R] grid: How to merge cells in grid.layout?

Bert Gunter gunter.berton at gene.com
Sun Sep 23 16:54:30 CEST 2012


Inline below.

On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert
<marius.hofert at math.ethz.ch> wrote:
> Dear grid expeRts,
>
> I would like to create a layout with grid that looks like the following, but with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and (3,1) (and (4,2) and (4,3)) combined to one cell (so that contents can easily be centered.
>
> How can this be achieved?
>
>     require(grid)
>     gl <- grid.layout(4, 4, widths=unit(c(1, 3, 3, 1), "cm"),
>                       heights=unit(c(1, 3, 3, 1), "cm"))
>     grid.show.layout(gl)
>
> My goal is to put 4 plots in the larger squares, create some labels in the boxes
> (1,2), (1,3), (2,4), (3,4), and put common x-axis and y-axis labels in the
> (combined) boxes (2,1), (3,1) and (4,2), (4,3).

Why don't the "layout.pos.row" and "layout.pos.col" arguments of
?viewport not do exactly what you appear to want? Perhaps I
misunderstand, but I think what you want to do is just create your
layout as above and then push the viewports you want by suitably
setting these arguments, and then just draw your plots.

 If you're serious about using grid, Murrell's Graphics book is
essential and probably will clarify these issues for you (better than
I can, anyway).

>
> With layout() one can simply cbind/rbind boxes to produce the desired
> result. With grid.layout() this seems not be the case. Maybe the workflow is
> differently here to get the desired result.

You appear to be mistaken. From ?grid.layout:

"This function must NOT be confused with the base R graphics function
layout. In particular, do not use layout in combination with Grid
graphics. The documentation for layout may provide some useful
information and this function should behave identically in comparable
situations. The grid.layout function has added the ability to specify
a broader range of units for row heights and column widths, and allows
for nested layouts (see viewport). "

Cheers,
Bert

>
> Cheers,
>
> Marius
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list