Format numbers as currency, rounding values to dollars or cents using a convenient heuristic.

label_dollar(accuracy = NULL, scale = 1, prefix = "$", suffix = "",
  big.mark = ",", decimal.mark = ".", trim = TRUE,
  largest_with_cents = 1e+05, negative_parens = FALSE, ...)

dollar_format(accuracy = NULL, scale = 1, prefix = "$",
  suffix = "", big.mark = ",", decimal.mark = ".", trim = TRUE,
  largest_with_cents = 1e+05, negative_parens = FALSE, ...)

dollar(x, accuracy = NULL, scale = 1, prefix = "$", suffix = "",
  big.mark = ",", decimal.mark = ".", trim = TRUE,
  largest_with_cents = 1e+05, negative_parens = FALSE, ...)

Arguments

accuracy, largest_with_cents

Number to round to. If NULL, the default, values will be rounded to the nearest integer, unless any of the values has non-zero fractional component (e.g. cents) and the largest value is less than largest_with_cents which by default is 100,000.

scale

A scaling factor: x will be multiplied by scale before formating. This is useful if the underlying data is very small or very large.

prefix, suffix

Symbols to display before and after value.

big.mark

Character used between every 3 digits to separate thousands.

decimal.mark

The character to be used to indicate the numeric decimal point.

trim

Logical, if FALSE, values are right-justified to a common width (see base::format()).

negative_parens

Display negative using parentheses?

...

Other arguments passed on to base::format().

x

A numeric vector

Value

All label_() functions return a "labelling" function, i.e. a function that takes a vector x and returns a character vector of length(x) giving a label for each input value.

Labelling functions are designed to be used with the labels argument of ggplot2 scales. The examples demonstrate their use with x scales, but they work similarly for all scales, including those that generate legends rather than axes.

Old interface

dollar() and format_dollar() are retired; please use label_dollar() instead.

See also

Examples

demo_continuous(c(0, 1), labels = label_dollar())
#> scale_x_continuous(labels = label_dollar())
demo_continuous(c(1, 100), labels = label_dollar())
#> scale_x_continuous(labels = label_dollar())
# Customise currency display with prefix and suffix demo_continuous(c(1, 100), labels = label_dollar(prefix = "USD "))
#> scale_x_continuous(labels = label_dollar(prefix = "USD "))
euro <- dollar_format( prefix = "", suffix = "\u20ac", big.mark = ".", decimal.mark = "," ) demo_continuous(c(1000, 1100), labels = euro)
#> scale_x_continuous(labels = euro)
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.000€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.025€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.050€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.075€' in 'mbcsToSbcs': dot substituted for <ac>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <e2>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <82>
#> Warning: conversion failure on '1.100€' in 'mbcsToSbcs': dot substituted for <ac>
# Use negative_parens = TRUE for finance style display demo_continuous(c(-100, 100), labels = label_dollar(negative_parens = TRUE))
#> scale_x_continuous(labels = label_dollar(negative_parens = TRUE))