Adaptive Figure Height for a Subgroup-Distribution Plot
Source:R/plot_sg_distribution.R
sgdist_fig_height.RdComputes a reasonable knitr fig.height (in inches) for a
plot_sg_distribution() panel based on the number of
bars, keeping the visual quality consistent across scenarios with
very different numbers of distinct subgroup labels.
Arguments
- n_bars
Integer. Number of bars in the plot, typically retrieved via
attr(p, "n_bars")on a plot returned byplot_sg_distribution().- floor_in
Numeric. Minimum height in inches. Default:
4.0.- ceil_in
Numeric. Maximum height in inches. Default:
10.0.- per_bar
Numeric. Height contribution per bar in inches. Default:
0.35.- base_in
Numeric. Base height added to
per_bar * n_barsbefore applying the floor / ceiling. Default:3.0.
Value
Numeric scalar, a height in inches in [floor_in,
ceil_in]. Suitable for the fig.height chunk option.
Examples
if (FALSE) { # \dontrun{
p <- plot_sg_distribution(results, placeholder_on_empty = TRUE)
h <- sgdist_fig_height(attr(p, "n_bars"))
# Use `h` as the fig.height chunk option.
} # }