Skip to contents

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

Usage

forest_dims(x, ..., units = c("in", "cm", "mm"))

Arguments

x

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

...

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

units

Units of the returned width and height. One of "in", "cm", or "mm". Defaults to "in".

Value

A named list with elements:

  • width: Forest plot width.

  • height: Forest plot height.

  • units: Units of width and height.

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.

Examples

# Create a simple meta-analysis object
m <- meta::metagen(
  TE = c(0.5, 0.8, 0.3),
  seTE = c(0.2, 0.3, 0.15),
  studlab = c("Study A", "Study B", "Study C")
)

# Get dimensions in inches (default)
forest_dims(m)
#> $width
#> [1] 8.768552
#> 
#> $height
#> [1] 3.2
#> 
#> $units
#> [1] "in"
#> 

# Get dimensions in centimetres
forest_dims(m, units = "cm")
#> $width
#> [1] 22.27212
#> 
#> $height
#> [1] 8.128
#> 
#> $units
#> [1] "cm"
#>