Title: | Arrange 'Grobs' in Tables |
---|---|
Description: | Tools to make it easier to work with "tables" of 'grobs'. The 'gtable' package defines a 'gtable' grob class that specifies a grid along with a list of grobs and their placement in the grid. Further the package makes it easy to manipulate and combine 'gtable' objects so that complex compositions can be built up sequentially. |
Authors: | Hadley Wickham [aut], Thomas Lin Pedersen [aut, cre], Posit Software, PBC [cph, fnd] |
Maintainer: | Thomas Lin Pedersen <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.6.9000 |
Built: | 2024-10-26 16:15:40 UTC |
Source: | https://github.com/r-lib/gtable |
Convert to a gtable
as.gtable(x, ...) ## S3 method for class 'grob' as.gtable(x, widths = NULL, heights = NULL, ...)
as.gtable(x, ...) ## S3 method for class 'grob' as.gtable(x, widths = NULL, heights = NULL, ...)
x |
An object to convert. |
... |
Arguments forwarded to methods. |
widths , heights
|
Scalar unit setting the size of the table. Defaults
to |
A gtable object
as.gtable(grob)
: Creates a 1-cell gtable containing the grob.
These functions are the parallels of the matrix
/data.frame
row and
column bindings. As such they work in the same way, except they have to take
care of additional attributes within the gtables. Most importantly it needs
to take care of the sizing of the final gtable, as the different gtables
going in may have different widths or heights. By default it tries to
calculate the maximum width/height among the supplied gtables, but other
options exists. Further, the relative layering of the grobs in each gtable
can be modified or left as-is.
## S3 method for class 'gtable' rbind(..., size = "max", z = NULL) ## S3 method for class 'gtable' cbind(..., size = "max", z = NULL)
## S3 method for class 'gtable' rbind(..., size = "max", z = NULL) ## S3 method for class 'gtable' cbind(..., size = "max", z = NULL)
... |
gtables to combine ( |
size |
How should the widths (for rbind) and the heights (for cbind)
be combined across the gtables: take values from |
z |
A numeric vector indicating the relative z values of each gtable.
The z values of each object in the resulting gtable will be modified
to fit this order. If |
A gtable object
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() row <- matrix(list(a, b), nrow = 1) col <- matrix(list(a, b), ncol = 1) mat <- matrix(list(a, b, c, nullGrob()), nrow = 2) row_gt <- gtable_matrix("demo", row, unit(c(1, 1), "null"), unit(1, "null")) col_gt <- gtable_matrix("demo", col, unit(1, "null"), unit(c(1, 1), "null")) mat_gt <- gtable_matrix("demo", mat, unit(c(1, 1), "null"), unit(c(1, 1), "null")) # cbind c_binded <- cbind(mat_gt, col_gt, size = "first") plot(c_binded) # rbind r_binded <- rbind(mat_gt, row_gt, size = "last") plot(r_binded) # Dimensions must match along bind direction try(cbind(mat_gt, row_gt))
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() row <- matrix(list(a, b), nrow = 1) col <- matrix(list(a, b), ncol = 1) mat <- matrix(list(a, b, c, nullGrob()), nrow = 2) row_gt <- gtable_matrix("demo", row, unit(c(1, 1), "null"), unit(1, "null")) col_gt <- gtable_matrix("demo", col, unit(1, "null"), unit(c(1, 1), "null")) mat_gt <- gtable_matrix("demo", mat, unit(c(1, 1), "null"), unit(c(1, 1), "null")) # cbind c_binded <- cbind(mat_gt, col_gt, size = "first") plot(c_binded) # rbind r_binded <- rbind(mat_gt, row_gt, size = "last") plot(r_binded) # Dimensions must match along bind direction try(cbind(mat_gt, row_gt))
A grob table captures all the information needed to layout grobs in a table structure. It supports row and column spanning, offers some tools to automatically figure out the correct dimensions, and makes it easy to align and combine multiple tables.
gtable( widths = list(), heights = list(), respect = FALSE, name = "layout", rownames = NULL, colnames = NULL, vp = NULL )
gtable( widths = list(), heights = list(), respect = FALSE, name = "layout", rownames = NULL, colnames = NULL, vp = NULL )
widths |
a unit vector giving the width of each column |
heights |
a unit vector giving the height of each row |
respect |
a logical vector of length 1: should the aspect ratio of
height and width specified in null units be respected. See
|
name |
a string giving the name of the table. This is used to name the layout viewport |
rownames , colnames
|
character vectors of row and column names, used for characteric subsetting. |
vp |
a grid viewport object (or NULL). |
Each grob is put in its own viewport - grobs in the same location are not combined into one cell. Each grob takes up the entire cell viewport so justification control is not available.
It constructs both the viewports and the gTree needed to display the table.
A gtable object
There are three basics components to a grob table: the specification of table (cell heights and widths), the layout (for each grob, its position, name and other settings), and global parameters.
It's easier to understand how gtable
works if in your head you keep
the table separate from it's contents. Each cell can have 0, 1, or many
grobs inside. Each grob must belong to at least one cell, but can span
across many cells.
The layout details are stored in a data frame with one row for each grob, and columns:
t
top extent of grob
r
right extent of grob
b
bottom extent of
l
left extent of grob
z
the z-order of the grob - used to reorder the grobs
before they are rendered
clip
a string, specifying how the grob should be clipped:
either "on"
, "off"
or "inherit"
name
, a character vector used to name each grob and its
viewport
You should not need to modify this data frame directly - instead use
functions like gtable_add_grob
.
Other gtable construction:
gtable_col()
,
gtable_matrix()
,
gtable_row()
,
gtable_spacer
library(grid) a <- gtable(unit(1:3, c("cm")), unit(5, "cm")) a gtable_show_layout(a) # Add a grob: rect <- rectGrob(gp = gpar(fill = "black")) a <- gtable_add_grob(a, rect, 1, 1) a plot(a) # gtables behave like matrices: dim(a) t(a) plot(t(a)) # when subsetting, grobs are retained if their extents lie in the # rows/columns that retained. b <- gtable(unit(c(2, 2, 2), "cm"), unit(c(2, 2, 2), "cm")) b <- gtable_add_grob(b, rect, 2, 2) b[1, ] b[, 1] b[2, 2] # gtable have row and column names rownames(b) <- 1:3 rownames(b)[2] <- 200 colnames(b) <- letters[1:3] dimnames(b)
library(grid) a <- gtable(unit(1:3, c("cm")), unit(5, "cm")) a gtable_show_layout(a) # Add a grob: rect <- rectGrob(gp = gpar(fill = "black")) a <- gtable_add_grob(a, rect, 1, 1) a plot(a) # gtables behave like matrices: dim(a) t(a) plot(t(a)) # when subsetting, grobs are retained if their extents lie in the # rows/columns that retained. b <- gtable(unit(c(2, 2, 2), "cm"), unit(c(2, 2, 2), "cm")) b <- gtable_add_grob(b, rect, 2, 2) b[1, ] b[, 1] b[2, 2] # gtable have row and column names rownames(b) <- 1:3 rownames(b)[2] <- 200 colnames(b) <- letters[1:3] dimnames(b)
Insert new columns in a gtable and adjust the grob placement accordingly. If columns are added in the middle of a grob spanning multiple columns, the grob will continue to span them all. If a column is added to the left or right of a grob, the grob will not span the new column(s).
gtable_add_cols(x, widths, pos = -1)
gtable_add_cols(x, widths, pos = -1)
x |
a |
widths |
a unit vector giving the widths of the new columns |
pos |
new columns will be added to the right of this position. Defaults
to adding col on right. |
A gtable with the new columns added.
Other gtable manipulation:
gtable_add_grob()
,
gtable_add_padding()
,
gtable_add_rows()
,
gtable_add_space
,
gtable_filter()
library(grid) rect <- rectGrob(gp = gpar(fill = "#00000080")) tab <- gtable(unit(rep(1, 3), "null"), unit(rep(1, 3), "null")) tab <- gtable_add_grob(tab, rect, t = 1, l = 1, r = 3) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 1) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 3) dim(tab) plot(tab) # Grobs will continue to span over new rows if added in the middle tab2 <- gtable_add_cols(tab, unit(1, "null"), 1) dim(tab2) plot(tab2) # But not when added to left (0) or right (-1, the default) tab3 <- gtable_add_cols(tab, unit(1, "null")) tab3 <- gtable_add_cols(tab3, unit(1, "null"), 0) dim(tab3) plot(tab3)
library(grid) rect <- rectGrob(gp = gpar(fill = "#00000080")) tab <- gtable(unit(rep(1, 3), "null"), unit(rep(1, 3), "null")) tab <- gtable_add_grob(tab, rect, t = 1, l = 1, r = 3) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 1) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 3) dim(tab) plot(tab) # Grobs will continue to span over new rows if added in the middle tab2 <- gtable_add_cols(tab, unit(1, "null"), 1) dim(tab2) plot(tab2) # But not when added to left (0) or right (-1, the default) tab3 <- gtable_add_cols(tab, unit(1, "null")) tab3 <- gtable_add_cols(tab3, unit(1, "null"), 0) dim(tab3) plot(tab3)
This only adds grobs into the table - it doesn't affect the table layout in any way. In the gtable model, grobs always fill up the complete table cell. If you want custom justification you might need to define the grob dimension in absolute units, or put it into another gtable that can then be added to the gtable instead of the grob.
gtable_add_grob( x, grobs, t, l, b = t, r = l, z = Inf, clip = "on", name = x$name )
gtable_add_grob( x, grobs, t, l, b = t, r = l, z = Inf, clip = "on", name = x$name )
x |
a |
grobs |
a single grob or a list of grobs |
t |
a numeric vector giving the top extent of the grobs |
l |
a numeric vector giving the left extent of the grobs |
b |
a numeric vector giving the bottom extent of the grobs |
r |
a numeric vector giving the right extent of the grobs |
z |
a numeric vector giving the order in which the grobs should be
plotted. Use |
clip |
should drawing be clipped to the specified cells
( |
name |
name of the grob - used to modify the grob name before it's plotted. |
A gtable object with the new grob(s) added
Other gtable manipulation:
gtable_add_cols()
,
gtable_add_padding()
,
gtable_add_rows()
,
gtable_add_space
,
gtable_filter()
library(grid) gt <- gtable(widths = unit(c(1, 1), 'null'), heights = unit(c(1, 1), 'null')) pts <- pointsGrob(x = runif(5), y = runif(5)) # Add a grob to a single cell (top-right cell) gt <- gtable_add_grob(gt, pts, t = 1, l = 2) # Add a grob spanning multiple cells gt <- gtable_add_grob(gt, pts, t = 1, l = 1, b = 2) plot(gt)
library(grid) gt <- gtable(widths = unit(c(1, 1), 'null'), heights = unit(c(1, 1), 'null')) pts <- pointsGrob(x = runif(5), y = runif(5)) # Add a grob to a single cell (top-right cell) gt <- gtable_add_grob(gt, pts, t = 1, l = 2) # Add a grob spanning multiple cells gt <- gtable_add_grob(gt, pts, t = 1, l = 1, b = 2) plot(gt)
This is a convenience function for adding an extra row and an extra column at each edge of the table.
gtable_add_padding(x, padding)
gtable_add_padding(x, padding)
x |
a |
padding |
vector of length 4: top, right, bottom, left. Normal recycling rules apply. |
A gtable object
Other gtable manipulation:
gtable_add_cols()
,
gtable_add_grob()
,
gtable_add_rows()
,
gtable_add_space
,
gtable_filter()
library(grid) gt <- gtable(unit(1, "null"), unit(1, "null")) gt <- gtable_add_grob(gt, rectGrob(gp = gpar(fill = "black")), 1, 1) plot(gt) plot(cbind(gt, gt)) plot(rbind(gt, gt)) pad <- gtable_add_padding(gt, unit(1, "cm")) plot(pad) plot(cbind(pad, pad)) plot(rbind(pad, pad))
library(grid) gt <- gtable(unit(1, "null"), unit(1, "null")) gt <- gtable_add_grob(gt, rectGrob(gp = gpar(fill = "black")), 1, 1) plot(gt) plot(cbind(gt, gt)) plot(rbind(gt, gt)) pad <- gtable_add_padding(gt, unit(1, "cm")) plot(pad) plot(cbind(pad, pad)) plot(rbind(pad, pad))
Insert new rows in a gtable and adjust the grob placement accordingly. If rows are added in the middle of a grob spanning multiple rows, the grob will continue to span them all. If a row is added above or below a grob, the grob will not span the new row(s).
gtable_add_rows(x, heights, pos = -1)
gtable_add_rows(x, heights, pos = -1)
x |
a |
heights |
a unit vector giving the heights of the new rows |
pos |
new row will be added below this position. Defaults to
adding row on bottom. |
A gtable with the new rows added.
Other gtable manipulation:
gtable_add_cols()
,
gtable_add_grob()
,
gtable_add_padding()
,
gtable_add_space
,
gtable_filter()
library(grid) rect <- rectGrob(gp = gpar(fill = "#00000080")) tab <- gtable(unit(rep(1, 3), "null"), unit(rep(1, 3), "null")) tab <- gtable_add_grob(tab, rect, t = 1, l = 1, r = 3) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 1) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 3) dim(tab) plot(tab) # Grobs will continue to span over new rows if added in the middle tab2 <- gtable_add_rows(tab, unit(1, "null"), 1) dim(tab2) plot(tab2) # But not when added to top (0) or bottom (-1, the default) tab3 <- gtable_add_rows(tab, unit(1, "null")) tab3 <- gtable_add_rows(tab3, unit(1, "null"), 0) dim(tab3) plot(tab3)
library(grid) rect <- rectGrob(gp = gpar(fill = "#00000080")) tab <- gtable(unit(rep(1, 3), "null"), unit(rep(1, 3), "null")) tab <- gtable_add_grob(tab, rect, t = 1, l = 1, r = 3) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 1) tab <- gtable_add_grob(tab, rect, t = 1, b = 3, l = 3) dim(tab) plot(tab) # Grobs will continue to span over new rows if added in the middle tab2 <- gtable_add_rows(tab, unit(1, "null"), 1) dim(tab2) plot(tab2) # But not when added to top (0) or bottom (-1, the default) tab3 <- gtable_add_rows(tab, unit(1, "null")) tab3 <- gtable_add_rows(tab3, unit(1, "null"), 0) dim(tab3) plot(tab3)
Adds width
space between the columns or height
space between
the rows, effictvely pushing the existing cells apart.
gtable_add_col_space(x, width) gtable_add_row_space(x, height)
gtable_add_col_space(x, width) gtable_add_row_space(x, height)
x |
a gtable object |
width |
a vector of units of length 1 or ncol - 1 |
height |
a vector of units of length 1 or nrow - 1 |
A gtable with the additional rows or columns added
Other gtable manipulation:
gtable_add_cols()
,
gtable_add_grob()
,
gtable_add_padding()
,
gtable_add_rows()
,
gtable_filter()
library(grid) rect <- rectGrob() rect_mat <- matrix(rep(list(rect), 9), nrow = 3) gt <- gtable_matrix("rects", rect_mat, widths = unit(rep(1, 3), "null"), heights = unit(rep(1, 3), "null")) plot(gt) # Add spacing between the grobs # same height between all rows gt <- gtable_add_row_space(gt, unit(0.5, "cm")) # Different width between the columns gt <- gtable_add_col_space(gt, unit(c(0.5, 1), "cm")) plot(gt)
library(grid) rect <- rectGrob() rect_mat <- matrix(rep(list(rect), 9), nrow = 3) gt <- gtable_matrix("rects", rect_mat, widths = unit(rep(1, 3), "null"), heights = unit(rep(1, 3), "null")) plot(gt) # Add spacing between the grobs # same height between all rows gt <- gtable_add_row_space(gt, unit(0.5, "cm")) # Different width between the columns gt <- gtable_add_col_space(gt, unit(c(0.5, 1), "cm")) plot(gt)
This function stacks a list of grobs into a single column gtable of the given width and heights.
gtable_col( name, grobs, width = NULL, heights = NULL, z = NULL, vp = NULL, clip = "inherit" )
gtable_col( name, grobs, width = NULL, heights = NULL, z = NULL, vp = NULL, clip = "inherit" )
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 |
width |
a unit vector giving the width of this column |
heights |
a unit vector giving the height of each row |
z |
a numeric vector giving the order in which the grobs should be
plotted. Use |
vp |
a grid viewport object (or NULL). |
clip |
should drawing be clipped to the specified cells
( |
A gtable with one column and as many rows as elements in the grobs list.
Other gtable construction:
gtable()
,
gtable_matrix()
,
gtable_row()
,
gtable_spacer
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() gt <- gtable_col("demo", list(a, b, c)) gt plot(gt) gtable_show_layout(gt)
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() gt <- gtable_col("demo", list(a, b, c)) gt plot(gt) gtable_show_layout(gt)
Normally a gtable is considered a matrix when indexing so that indexing is
working on the cell layout and not on the grobs it contains. gtable_filter
allows you to subset the grobs by name and optionally remove rows or columns
if left empty after the subsetting
gtable_filter(x, pattern, fixed = FALSE, trim = TRUE, invert = FALSE)
gtable_filter(x, pattern, fixed = FALSE, trim = TRUE, invert = FALSE)
x |
a gtable object |
pattern |
character string containing a regular expression
(or character string for |
fixed |
logical. If |
trim |
if |
invert |
Should the filtering be inverted so that cells matching
|
A gtable only containing the matching grobs, potentially stripped of empty columns and rows
Other gtable manipulation:
gtable_add_cols()
,
gtable_add_grob()
,
gtable_add_padding()
,
gtable_add_rows()
,
gtable_add_space
library(grid) gt <- gtable(unit(rep(5, 3), c("cm")), unit(5, "cm")) rect <- rectGrob(gp = gpar(fill = "black")) circ <- circleGrob(gp = gpar(fill = "red")) gt <- gtable_add_grob(gt, rect, 1, 1, name = "rect") gt <- gtable_add_grob(gt, circ, 1, 3, name = "circ") plot(gtable_filter(gt, "rect")) plot(gtable_filter(gt, "rect", trim = FALSE)) plot(gtable_filter(gt, "circ")) plot(gtable_filter(gt, "circ", trim = FALSE))
library(grid) gt <- gtable(unit(rep(5, 3), c("cm")), unit(5, "cm")) rect <- rectGrob(gp = gpar(fill = "black")) circ <- circleGrob(gp = gpar(fill = "red")) gt <- gtable_add_grob(gt, rect, 1, 1, name = "rect") gt <- gtable_add_grob(gt, circ, 1, 3, name = "circ") plot(gtable_filter(gt, "rect")) plot(gtable_filter(gt, "rect", trim = FALSE)) plot(gtable_filter(gt, "circ")) plot(gtable_filter(gt, "circ", trim = FALSE))
Note that unlike heightDetails.gtable, this can return relative units.
gtable_height(x)
gtable_height(x)
x |
A gtable object |
This function takes a matrix of grobs and create a gtable matching with the grobs in the same position as they were in the matrix, with the given heights and widths.
gtable_matrix( name, grobs, widths = NULL, heights = NULL, z = NULL, respect = FALSE, clip = "on", vp = NULL )
gtable_matrix( name, grobs, widths = NULL, heights = NULL, z = NULL, respect = FALSE, clip = "on", vp = NULL )
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 |
respect |
a logical vector of length 1: should the aspect ratio of
height and width specified in null units be respected. See
|
clip |
should drawing be clipped to the specified cells
( |
vp |
a grid viewport object (or NULL). |
A gtable of the same dimensions as the grobs matrix.
Other gtable construction:
gtable()
,
gtable_col()
,
gtable_row()
,
gtable_spacer
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)
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)
This function puts grobs in a list side-by-side in a single-row gtable from left to right witrh the given widths and height.
gtable_row( name, grobs, height = NULL, widths = NULL, z = NULL, vp = NULL, clip = "inherit" )
gtable_row( name, grobs, height = NULL, widths = NULL, z = NULL, vp = NULL, clip = "inherit" )
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 |
height |
a unit vector giving the height of this row |
widths |
a unit vector giving the width of each column |
z |
a numeric vector giving the order in which the grobs should be
plotted. Use |
vp |
a grid viewport object (or NULL). |
clip |
should drawing be clipped to the specified cells
( |
A gtable with a single row and the same number of columns as elements in the grobs list
Other gtable construction:
gtable()
,
gtable_col()
,
gtable_matrix()
,
gtable_spacer
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() gt <- gtable_row("demo", list(a, b, c)) gt plot(gt) gtable_show_layout(gt)
library(grid) a <- rectGrob(gp = gpar(fill = "red")) b <- circleGrob() c <- linesGrob() gt <- gtable_row("demo", list(a, b, c)) gt plot(gt) gtable_show_layout(gt)
This function is a simple wrapper around grid::grid.show.layout()
that
allows you to inspect the layout of the gtable.
gtable_show_layout(x, ...)
gtable_show_layout(x, ...)
x |
a gtable object |
... |
Arguments passed on to
|
gt <- gtable(widths = grid::unit(c(1, 0.5, 2), c("null", "cm", "null")), heights = grid::unit(c(0.2, 1, 3), c("inch", "null", "cm"))) gtable_show_layout(gt)
gt <- gtable(widths = grid::unit(c(1, 0.5, 2), c("null", "cm", "null")), heights = grid::unit(c(0.2, 1, 3), c("inch", "null", "cm"))) gtable_show_layout(gt)
Create a zero-column or zero-row gtable with the given heights or widths respectively.
gtable_row_spacer(widths) gtable_col_spacer(heights)
gtable_row_spacer(widths) gtable_col_spacer(heights)
widths |
unit vector of widths |
heights |
unit vector of heights |
A gtable object
Other gtable construction:
gtable()
,
gtable_col()
,
gtable_matrix()
,
gtable_row()
This function detects rows and columns that does not contain any grobs and removes thewm from the gtable. If the rows and/or columns removed had a non-zero height/width the relative layout of the gtable may change.
gtable_trim(x)
gtable_trim(x)
x |
a gtable object |
A gtable object
library(grid) rect <- rectGrob(gp = gpar(fill = "black")) base <- gtable(unit(c(2, 2, 2), "cm"), unit(c(2, 2, 2), "cm")) center <- gtable_add_grob(base, rect, 2, 2) plot(center) plot(gtable_trim(center)) col <- gtable_add_grob(base, rect, 1, 2, 3, 2) plot(col) plot(gtable_trim(col)) row <- gtable_add_grob(base, rect, 2, 1, 2, 3) plot(row) plot(gtable_trim(row))
library(grid) rect <- rectGrob(gp = gpar(fill = "black")) base <- gtable(unit(c(2, 2, 2), "cm"), unit(c(2, 2, 2), "cm")) center <- gtable_add_grob(base, rect, 2, 2) plot(center) plot(gtable_trim(center)) col <- gtable_add_grob(base, rect, 1, 2, 3, 2) plot(col) plot(gtable_trim(col)) row <- gtable_add_grob(base, rect, 2, 1, 2, 3) plot(row) plot(gtable_trim(row))
Note that unlike widthDetails.gtable, this can return relative units.
gtable_width(x)
gtable_width(x)
x |
A gtable object |
Is this a gtable?
is.gtable(x)
is.gtable(x)
x |
object to test |
Print a gtable object
## S3 method for class 'gtable' print(x, zsort = FALSE, ...)
## S3 method for class 'gtable' print(x, zsort = FALSE, ...)
x |
A gtable object. |
zsort |
Sort by z values? Default |
... |
Other arguments (not used by this method). |