gg_GetPlotDims: Get dimensions of a ggplot2 object or derived gtable

View source: R/gg_GetPlotDims.R

gg_GetPlotDimsR Documentation

Get dimensions of a ggplot2 object or derived gtable

Description

Function to get dimensions of a ggplot2 object or derived gtable.

Usage

gg_GetPlotDims(
  p,
  unit = "in",
  null = 3,
  null_x = NULL,
  null_y = NULL,
  returnAll = FALSE,
  verbose = 0
)

Arguments

p
  • ggplot2 or derived gtable object

unit
  • plot units ("in", "cm", etc.)

null
  • size of (x and y) null (resizeable) units (in plot units; overridden if null_x and null_y are given)

null_x
  • size of horizontal null (resizeable) units (in plot units; must also specify null_y)

null_y
  • size of vertical (resizeable) units (in plot units; must also specify null_x)

returnAll
  • flag to return all information (not just dimensions)

verbose
  • flag (0,1,2) to print intermediate information (0=off)

Details

This function converts "null" (relative) scales in a ggplot2 object (or derived gtable) to absolute scales.

If either null_x or null_y is NULL, then the value of null is used for both. If both null_x and null_y are not NULL, these values are used for nulls along the corresponding axes.

Value

if returnAll is FALSE, returns a vector with plot width and height. Otherwise, it invisibly returns a list with elements dims - vector with plot width and height lyt - layout table tbl_rows - row dimensions tbl_cols - column dimensions tbl_matp -tibble with intermediate information tbl_matpp - tibble with intermediate information

Note

This does not work (yet) for composite figures consisting of multiple ggplot2 objects.

Author(s)

William Stockhausen (william.stockhausen@noaa.gov)


wStockhausen/wtsUtilities documentation built on March 16, 2024, 10:38 a.m.