Returns the height of a figure that a chart of plot_normal fills
exactly at a given width, with no empty margins, to save it with ggplot2::ggsave().
Usage
plot_normal_height(
plot = plot_normal(),
width = 7,
units = c("in", "cm", "mm")
)Arguments
- plot
A chart of
plot_normal, or any ggplot with a fixed aspect ratio.- width
The width of the figure.
- units
The units of
widthand of the height returned:"in","cm"or"mm".
Details
The chart keeps a fixed aspect ratio, but the column of the names of the scales, the text and the margins keep their size whatever the size of the figure, so the height that fits depends on the width, on the number of scales and on the length of their names. The function lays the chart out at the given width, measuring its text as a PDF does, and adds up the heights. Other graphics devices measure text a little differently, which can leave a margin of a fraction of a millimeter.
Examples
plot_normal_height(plot_normal(), 7)
#> [1] 3.207665
plot_normal_height(plot_normal(), 17.8, units = "cm")
#> [1] 8.158479
# fewer scales, a shorter chart
scales <- standard_normal_scales_data()
p <- plot_normal(scales[scales$scale %in% c("z", "T", "IQ"), ])
plot_normal_height(p, 7)
#> [1] 2.655741
ggsave(file.path(tempdir(), "normal.pdf"), p, width = 7, height = plot_normal_height(p, 7))