Learn R Programming

useful (version 1.2.7)

multiple: multiple

Description

Order of Magnitude Formatter

Usage

multiple(
  x,
  multiple = c("K", "M", "B", "T", "H", "k", "m", "b", "t", "h"),
  extra = scales::comma,
  digits = 0,
  ...
)

Value

Character vector of formatted numbers.

Arguments

x

Vector of numbers to be formatted.

multiple

The multiple to display numbers in. This symbol will be added to the end of the numbers.

extra

Function for perform any further formatting.

digits

Number of decimal places for rounding. This does not necessarily affect the number digits displayed, for this, supply accuracy in the form of accuracy=0.00001.

...

Extra arguments passed to extra, such as accuracy.

Author

Jared P. Lander

Details

This divides the number by the appropriate amount and adds on the corresponding symbol at the end of the number.

Examples

Run this code

require(scales)
vect <- c(1000, 1500, 23450, 21784, 875003780)
multiple(vect)
multiple(vect, extra=dollar)
multiple(vect, extra=identity)

require(ggplot2)
data(diamonds)
ggplot(diamonds, aes(x=x, y=y, color=price*100)) + geom_point() + 
scale_color_gradient2(labels=multiple)

Run the code above in your browser using DataLab