human_numbers: Human Numbers

Description Usage Arguments Value Source Examples

Description

Format numbers so they're legible for humans Use this in ggplot for labels where you might use the comma or percent functions from the Scales package.

Checks whether numbers are positive or negative. Allows up to 1 significant figure sapply used for element-wise application of the humanity function as a vector may include numbers where billions, millions or thousands are appropriate.

Usage

1
2
3
4
5
6
7
8
9
human_numbers(x = NULL, smbl = "", signif = 1)

scale_y_human(..., smbl = "", signif = 1)

scale_x_human(..., smbl = "", signif = 1)

human_num(x)

human_usd(x)

Arguments

x

a numeric vector to format,

smbl

a symbol you'd like to prefix your numbers by e.g. "$"

signif

the number of significant places you want the function to return

...

other arguments passed to scale_*_continuous

Value

a character vector the same length as the input vector

Source

https://github.com/fdryan/R/blob/master/ggplot2_formatter.r

Examples

1
2
3
4
5
6
7
8
9
human_numbers(c(1000000 , 1500000, 10000000000))
human_numbers(c(1.200000e+05, -2.154660e+05, 2.387790e+05, 4.343500e+04 ,5.648675e+12), "$")
## Not run: 
ggplot2 + scale_y_continuous(labels = human_numbers)
ggplot2 + scale_x_continuous(labels = human_numbers)
ggplot2 + scale_y_human()
ggplot2 + scale_x_human()

## End(Not run)

KevinRPan/handy documentation built on May 4, 2019, 2:34 p.m.