format2 | R Documentation |
format
settings and Dutch defaultsFormatting with readable format
settings and Dutch defaults
format2(x, ...)
## Default S3 method:
format2(x, ...)
## S3 method for class 'numeric'
format2(
x,
round = ifelse(percent, 1, 2),
force_decimals = ifelse(percent, TRUE, FALSE),
decimal.mark = dec_mark(),
big.mark = big_mark(),
min_length = 0,
percent = FALSE,
...
)
## S3 method for class 'percentage'
format2(
x,
round = 1,
force_decimals = TRUE,
decimal.mark = dec_mark(),
big.mark = big_mark(),
...
)
## S3 method for class 'Date'
format2(x, format = "d mmmm yyyy", locale = "nl", ...)
## S3 method for class 'POSIXt'
format2(x, format = "yyyy-mm-dd HH:MM:SS", locale = "nl", ...)
## S3 method for class 'hms'
format2(x, format = "HH:MM:SS", ...)
## S3 method for class 'difftime'
format2(
x,
round = 2,
force_decimals = FALSE,
decimal.mark = dec_mark(),
big.mark = big_mark(),
...
)
## S3 method for class 'object_size'
format2(x, round = 1, decimal.mark = dec_mark(), ...)
format2_scientific(x, round = 2, decimal.mark = dec_mark(), ...)
x |
vector of values |
... |
arguments given to methods such as |
round |
number of decimals to round to |
force_decimals |
force printing decimals, even with trailing zeroes |
decimal.mark , big.mark |
decimal and thousands limiters |
min_length |
minimal length of output, overwrites |
percent |
logical to transform numeric to percentage (character) |
format |
format to use, can be set with human-readable text such as |
locale |
language to set for dates |
The format2_scientific()
function returns an expression and can be used in ggplot2
plots.
format2()
always returns a character.
format2("2021-01-01")
format2("2021-01-01", "yyyy-qq")
format2(Sys.time(), "d mmmm yyyy HH:MM")
# content-aware of decimal use
format2(1024)
format2(c(1024, 0.123))
format2(2.1)
format2(2.1, force_decimals = TRUE) # since default is 2 decimals
p <- cleaner::as.percentage(0.123)
format2(p)
format2_scientific(c(12345, 12345678))
format2_scientific(c(12345, 12345678), round = 1)
# use format2_scientific for scientific labels in plots:
if (require("certeplot2")) {
# y axis without scientific notation
plot2(mtcars,
y = hp * 1000)
# y axis with scientific notation
plot2(mtcars,
y = hp * 1000,
y.labels = format2_scientific)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.