label_number_hdx {gghdx} | R Documentation |
Label numbers in HDX key figures style
Description
Formats numeric vector in the Centre style for key figures, which abbreviates numbers 1,000 and above to X.YK, 10,000 and above to XYK, 100,000 and above to XYZK, and the same for 1,000,000 and above, replacing the K with an M, and the same for B. Details of the data viz style can be found in the visualization guidelines
Usage
label_number_hdx(additional_prefix = "")
Arguments
additional_prefix |
Additional prefix to add to string, that will come
between |
Details
Just for continuity, values are labeled with T for trillion, and that is the maximum formatting available, anything above the trillions will continue to be truncated to report in the trillions.
Deals with negative values in case those ever need to be formatted in similar
manners. Also ensures that rounding is performed so numbers look correct.
Not to be used for percents, which should just use scales::label_percent()
.
Designed like the scales::
family of label functions, the return value of
label_number_hdx
is a function, based on the additional_prefix
. So you
should pass it in to scales_...()
labels
parameter in the same way as
scales_...()
Value
Returns a "labelling" function, in the same way as scales::label_...()
functions work, i.e. a function that takes x
and returns a labelled character
vector of length(x)
.
Examples
library(ggplot2)
# discrete scaling
p <- ggplot(txhousing) +
geom_point(
aes(
x = median,
y = volume
)
)
p
p +
scale_x_continuous(
labels = label_number_hdx("$")
) +
scale_y_continuous(
labels = label_number_hdx()
)