multipanelfigure (version 2.1.2)

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.

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

multi_panel_figure, save_multi_panel_figure

Examples

Run this code
# NOT RUN {
# 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 RUN {
 # Not testing due to use of external software
utils::browseURL(tmp_file)
# }

Run the code above in your browser using DataLab