pretty_num: Pretty print scaled numbers

Description Usage Arguments Functions Examples

View source: R/misc.R

Description

Pretty print scaled numbers

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
pretty_num(
  x,
  units = c(k = 1000, M = 1e+06, B = 1e+09),
  decimal_digits = 1,
  no_dot_zero = FALSE
)

format_pretty_num(
  units = c(k = 1000, M = 1e+06, B = 1e+09),
  decimal_digits = 1,
  no_dot_zero = TRUE
)

Arguments

x

Vector of numbers

units

Named list with lower bounds for units. Names are units or unit abbreviations.

decimal_digits

Number of digits to show after the decimal point in the selected unit.

no_dot_zero

Should trailing .0 be removed regardless of the decimal digits requested?

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
pretty_num(1234)
pretty_num(12345, decimal_digits = 3)
pretty_num(123456789)
pretty_num(12345678900)
pretty_num(c(1234, 1234567, 12345678900))

library(ggplot2)
ggplot(mtcars) +
  aes(mpg, wt * 1000) +
  geom_point() +
  scale_y_continuous(labels = format_pretty_num())

GerkeLab/grkmisc documentation built on Feb. 23, 2020, 6:50 a.m.