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

Marius Hofert marius.hofert at math.ethz.ch
Sun Sep 23 10:41:16 CEST 2012


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).

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.

Cheers,

Marius



More information about the R-help mailing list