Visualization functions

make_qty_text_labeller(q, unit = NULL, signif = 3)

Arguments

q

the quantity for which to generate a text labeller

unit

the unit (or units) in which to represent the quantity on the plot. By default uses the best metric prefix for each value of the quantity, which is good for generating orders of magnitude scales e.g. from mg to g to kg. If provided, uses the specified unit or units (need to be compatible with the quantity) for all values.

signif

number of significant digits for printing the quantity

Functions

  • make_qty_text_labeller: This is a useful labeller function for ggplots to generate quantity text labels on discrete scales and facets in the used created by get_qty_text. Supports both best metric for each label (simply don't provide the unit parameter) or a specify unit (specify the unit parameter).

Examples

# native unit labels q <- qty(c(0.1, 10, 1000), "mg") l <- make_qty_text_labeller(q) l(q) # test how labels would look
#> [1] "100 µg" "10 mg" "1 g"
# dual unit labels q <- qty(seq(0, 1000, by = 100), "K") l <- make_qty_text_labeller(q, unit = c("K", "C")) l(q) # test how the labels would look
#> [1] "0 K\n-273 C" "100 K\n-173 C" "200 K\n-73.1 C" "300 K\n26.9 C" #> [5] "400 K\n127 C" "500 K\n227 C" "600 K\n327 C" "700 K\n427 C" #> [9] "800 K\n527 C" "900 K\n627 C" "1000 K\n727 C"