The true minus sign (UTF 2212) -- neither an em dash, nor an en dash, nor the usual hyphen-minus -- is highly underrated. It just makes everything look better! This function builds on the formatting functions from the scales package by replacing the hyphen-minus with a true minus, and adding a plus sign if desired.

signs(..., format = scales::number, plus_sign = FALSE)

Arguments

...

Numeric vector and any other arguments passed to format.

format

Function that formats a numeric vector, such as scales::number, scales::comma, scales::percent, or a function returned by scales::unit_format (all of which are documented at number_format).

plus_sign

Logical. Should positive values start with plus signs?

Value

A UTF-8 character vector

Examples

signs(seq(-5, 5))
#> [1] "-5" "-4" "-3" "-2" "-1" "0" "1" "2" "3" "4" "5"
signs(seq(-5, 5), plus_sign = TRUE)
#> [1] "-5" "-4" "-3" "-2" "-1" "0" "+1" "+2" "+3" "+4" "+5"
signs(seq(-5, 5) / 100, format = scales::percent, plus_sign = TRUE)
#> [1] "-5.0%" "-4.0%" "-3.0%" "-2.0%" "-1.0%" "+0.0%" "+1.0%" "+2.0%" "+3.0%" #> [10] "+4.0%" "+5.0%"