forest_dims: Auxiliary functions to calculate the dimensions of a forest...

View source: R/forest_dims.R

forest_dimsR Documentation

Auxiliary functions to calculate the dimensions of a forest plot

Description

Extracts the exact width and height of a 'meta' forest plot from its internal grid layout. This is primarily used to determine the optimal dimensions for saving the forest plot to a file.

Usage

forest_dims(x, ..., units = "in")

units2inches(x, units = "in", dpi = 300)

inches2units(x, units = "in", dpi = 300)

Arguments

x

An object of class meta (e.g., from metacont, metabin, or metagen).

...

Additional arguments passed on to the underlying forest plot method (e.g., forest.meta, forest.metabind, forest.metacum, or forest.metainf).

units

Units of the returned 'width' and 'height'. One of "in" (for inches, default), "cm", or "mm", can be abbreviated. In inches2units and units2inches, "px" (for pixels) is also admissible.

dpi

Plot resolution.

Details

Rather than using guesswork or manual row counting, 'forest_dims()' captures the forest plot as a true graphics object and extracts the precise width and height directly from its underlying structure.

Because it mathematically measures the actual rendered components, it is highly robust. It works seamlessly with any forest plot configuration.

Value

A named list with elements:

width

Forest plot width.

height

Forest plot height.

units

Units of 'width' and 'height'.

Author(s)

Nour Edin Darwish nouredindarwish@gmail.com

Examples

# Create a simple meta-analysis object
ma <- metagen(TE = c(0.5, 0.8, 0.3), seTE = c(0.2, 0.3, 0.15),
  studlab = paste("Study", LETTERS[1:3]))

# Get dimensions in inches (default)
forest_dims(ma)

# Get dimensions in centimetres
forest_dims(ma, units = "cm")

# Forest plot with details on meta-analysis methods
forest_dims(ma, details = TRUE, units = "cm")


meta documentation built on May 25, 2026, 9:07 a.m.