| label_bytes | R Documentation |
Scale bytes into human friendly units. Can use either SI units (e.g. kB = 1000 bytes) or binary units (e.g. kiB = 1024 bytes). See Units of Information on Wikipedia for more details.
label_bytes(units = "auto_si", accuracy = 1, scale = 1, ...)
units |
Unit to use. Should either one of:
|
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale |
A scaling factor: |
... |
Arguments passed on to
|
All label_() functions return a "labelling" function, i.e. a function that
takes a vector x and returns a character vector of length(x) giving a
label for each input value.
Labelling functions are designed to be used with the labels argument of
ggplot2 scales. The examples demonstrate their use with x scales, but
they work similarly for all scales, including those that generate legends
rather than axes.
Other labels for continuous scales:
label_currency(),
label_glue(),
label_number_auto(),
label_number_si(),
label_ordinal(),
label_parse(),
label_percent(),
label_pvalue(),
label_scientific()
Other labels for log scales:
label_log(),
label_number_si(),
label_scientific()
demo_continuous(c(1, 1e6))
demo_continuous(c(1, 1e6), labels = label_bytes())
# Auto units are particularly nice on log scales
demo_log10(c(1, 1e7), labels = label_bytes())
# You can also set the units
demo_continuous(c(1, 1e6), labels = label_bytes("kB"))
# You can also use binary units where a megabyte is defined as
# (1024) ^ 2 bytes rather than (1000) ^ 2. You'll need to override
# the default breaks to make this more informative.
demo_continuous(c(1, 1024^2),
breaks = breaks_width(250 * 1024),
labels = label_bytes("auto_binary")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.