Pretty print scaled numbers
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 )
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 |
format_pretty_num
: A label formatter for ggplot2
pretty_num(1234)#> [1] "1.2k"pretty_num(12345, decimal_digits = 3)#> [1] "12.345k"pretty_num(123456789)#> [1] "123.5M"pretty_num(12345678900)#> [1] "12.3B"#> [1] "1.2k" "1.2M" "12.3B"library(ggplot2) ggplot(mtcars) + aes(mpg, wt * 1000) + geom_point() + scale_y_continuous(labels = format_pretty_num())