Standardise the width in ggplot2 geoms so that widths appear visually
consistent across plots with different numbers of categories, panel dimensions,
and orientations.
This can be used in geoms such as ggplot2::geom_bar(),
ggplot2::geom_col(), ggplot2::geom_boxplot(),
and ggplot2::geom_errorbar().
The relevant panel dimension must be an absolute physical unit (for example
grid::unit(..., "mm")), either supplied directly or set in the current theme.
Relative units are not supported.
Usage
get_width(
...,
n = NULL,
n_dodge = NULL,
orientation = c("x", "y"),
equiwidth = NULL,
panel_widths = NULL,
panel_heights = NULL
)Arguments
- ...
Must be empty. Forces all other arguments to be named and allows trailing commas.
- n
Number of categories in the orientation aesthetic (that is,
"x"or"y"). For faceted plots, use the maximumnacross facets.- n_dodge
Number of dodge categories. Intended for use with
position_dodge(preserve = "single").- orientation
Orientation:
"x"for vertical geoms,"y"for horizontal geoms.- equiwidth
Numeric scaling factor controlling apparent width. A value of
1is the default. Increase to make a wider appearance; decrease to make a thinner appearance. IfNULL, uses the value set byset_equiwidth(), falling back to1.- panel_widths
A
grid::unitobject specifying panel widths. IfNULL, uses the value from the current theme.- panel_heights
A
grid::unitobject specifying panel heights. IfNULL, uses the value from the current theme.
Value
A single numeric width suitable for the width argument of geoms such
as ggplot2::geom_bar() or ggplot2::geom_col().