gtable_matrix: Create a gtable from a matrix of grobs.

Description Usage Arguments Examples

View source: R/gtable-layouts.r

Description

Create a gtable from a matrix of grobs.

Usage

1
2
gtable_matrix(name, grobs, widths = NULL, heights = NULL, z = NULL,
  respect = FALSE, clip = "on", vp = NULL)

Arguments

name

a string giving the name of the table. This is used to name the layout viewport

grobs

a single grob or a list of grobs

widths

a unit vector giving the width of each column

heights

a unit vector giving the height of each row

z

a numeric matrix of the same dimensions as grobs, specifying the order that the grobs are drawn.

respect

a logical vector of length 1: should the aspect ratio of height and width specified in null units be respected. See grid.layout for more details

clip

should drawing be clipped to the specified cells ("on"), the entire table ("inherit"), or not at all ("off")

vp

a grid viewport object (or NULL).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(grid)
a <- rectGrob(gp = gpar(fill = "red"))
b <- circleGrob()
c <- linesGrob()

row <- matrix(list(a, b, c), nrow = 1)
col <- matrix(list(a, b, c), ncol = 1)
mat <- matrix(list(a, b, c, nullGrob()), nrow = 2)

gtable_matrix("demo", row, unit(c(1, 1, 1), "null"), unit(1, "null"))
gtable_matrix("demo", col, unit(1, "null"), unit(c(1, 1, 1), "null"))
gtable_matrix("demo", mat, unit(c(1, 1), "null"), unit(c(1, 1), "null"))

# Can specify z ordering
z <- matrix(c(3, 1, 2, 4), nrow = 2)
gtable_matrix("demo", mat, unit(c(1, 1), "null"), unit(c(1, 1), "null"), z = z)

Example output

TableGrob (1 x 3) "demo": 3 grobs
  z     cells name                  grob
1 1 (1-1,1-1) demo     rect[GRID.rect.1]
2 2 (1-1,2-2) demo circle[GRID.circle.2]
3 3 (1-1,3-3) demo   lines[GRID.lines.3]
TableGrob (3 x 1) "demo": 3 grobs
  z     cells name                  grob
1 1 (1-1,1-1) demo     rect[GRID.rect.1]
2 2 (2-2,1-1) demo circle[GRID.circle.2]
3 3 (3-3,1-1) demo   lines[GRID.lines.3]
TableGrob (2 x 2) "demo": 4 grobs
  z     cells name                  grob
1 1 (1-1,1-1) demo     rect[GRID.rect.1]
2 2 (2-2,1-1) demo circle[GRID.circle.2]
3 3 (1-1,2-2) demo   lines[GRID.lines.3]
4 4 (2-2,2-2) demo     null[GRID.null.4]
TableGrob (2 x 2) "demo": 4 grobs
  z     cells name                  grob
1 3 (1-1,1-1) demo     rect[GRID.rect.1]
2 1 (2-2,1-1) demo circle[GRID.circle.2]
3 2 (1-1,2-2) demo   lines[GRID.lines.3]
4 4 (2-2,2-2) demo     null[GRID.null.4]

gtable documentation built on May 29, 2017, 6:47 p.m.

Search within the gtable package
Search all R packages, documentation and source code