R/utils_grid.R

Defines functions split_widths_cm split_heights_cm

# Splits a list of grobs and reports max height in cm per level
split_heights_cm <- function(grobs, split) {
  vals <- lapply(grobs, grobHeight)
  vals <- vapply(vals,  convertHeight, numeric(1),
                 unitTo = "cm", valueOnly = TRUE)
  vals <- unname(vapply(split(vals, split, drop = TRUE), max, numeric(1)))
  unit(vals, "cm")
}

# Splits a list of grobs and reports max width in cm per level
split_widths_cm <- function(grobs, split) {
  vals <- lapply(grobs, grobWidth)
  vals <- vapply(vals,  convertWidth, numeric(1),
                 unitTo = "cm", valueOnly = TRUE)
  vals <- unname(vapply(split(vals, split, drop = TRUE), max, numeric(1)))
  unit(vals, "cm")
}

Try the ggh4x package in your browser

Any scripts or data that you put into this service are public.

ggh4x documentation built on Aug. 31, 2023, 1:08 a.m.