Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

grob_dimensions

Convenient Access to grob Dimensions


Description

Convenience functions extracting dimensions from grob objects.

Usage

figure_width(grob, unit_to = "mm")
figure_height(grob, unit_to = "mm")

Arguments

grob

A grob object for which dimensions are to be retrieved.

unit_to

A single character string representing a valid grid-unit.

Value

Single numeric objects are returned.

Author(s)

Johannes Graumann

References

Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03

See Also

Examples

# Get dimensions of a grid grob
a_circle <- grid::circleGrob(x = 15, y = 30, r = 15, default.unit = "mm")
figure_height(a_circle)
figure_width(a_circle)

# Use the unit_to arg to convert units
figure_height(a_circle, unit_to = "in")
figure_width(a_circle, unit_to = "cm")

# Get dimensions of a multi-panel figure
figure <- multi_panel_figure(width = 55, height = 55, rows = 2, columns = 2)
figure_height(figure)
figure_width(figure)

# ggsave defaults to measuring dimensions in inches
width <- figure_width(figure, unit_to = "in")
height <- figure_height(figure, unit_to = "in")
tmp_file <- tempfile(fileext = ".png")
ggplot2::ggsave(
  tmp_file, gtable::gtable_show_layout(figure),
  width = width, height = height
)
 # Not testing due to use of external software
utils::browseURL(tmp_file)

multipanelfigure

Infrastructure to Assemble Multi-Panel Figures (from Grobs)

v2.1.2
GPL (>= 3)
Authors
Johannes Graumann [cre, aut], Richard Cotton [ctb]
Initial release
2020-03-04

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.