Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

label_bytes

Label bytes (1 kb, 2 MB, etc)


Description

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.

Usage

label_bytes(units = "auto_si", accuracy = 1, ...)

Arguments

units

Unit to use. Should either one of:

  • "kB", "MB", "GB", "TB", "PB", "EB", "ZB", and "YB" for SI units (base 1000).

  • "kiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", and "YiB" for binary units (base 1024).

  • auto_si or auto_binary to automatically pick the most approrpiate unit for each value.

accuracy

A number to round to. Use (e.g.) 0.01 to show 2 decimal places of precision. If NULL, the default, uses a heuristic that should ensure breaks have the minimum number of digits needed to show the difference between adjacent values.

Applied to rescaled data.

...

Other arguments passed on to number()

Value

A labeller function that takes a numeric vector of breaks and returns a character vector of labels.

See Also

Other labels for log scales: label_number_si(), label_scientific()

Examples

demo_continuous(c(1, 1e6))
demo_continuous(c(1, 1e6), label = label_bytes())
# Force all to use same units
demo_continuous(c(1, 1e6), label = label_bytes("kB"))

# Auto units are particularly nice on log scales
demo_log10(c(1, 1e6))
demo_log10(c(1, 1e7), label = label_bytes())

# 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), label = label_bytes("auto_binary"))
demo_continuous(c(1, 1024^2),
  breaks = breaks_width(250 * 1024),
  label = label_bytes("auto_binary")
)

scales

Scale Functions for Visualization

v1.1.1
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], Dana Seidel [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.