f_year {numform} | R Documentation |
Format Years
Description
Format 4 digit integer, date, or POSIXlt formats to 2 or 4 digit years.
Usage
f_year(x, digits = 2, ...)
## S3 method for class 'numeric'
f_year(x, digits = 2, ...)
## S3 method for class 'Date'
f_year(x, digits = 2, ...)
## S3 method for class 'POSIXt'
f_year(x, digits = 2, ...)
## S3 method for class 'hms'
f_year(x, digits = 2, ...)
ff_year(digits = 2, ...)
Arguments
x |
A vector of 4 digits integers, dates, or POSIXlt. |
digits |
Either 2 or 4 for the number of digits to make the year. |
... |
ignored. |
Value
Returns a vector of two or four digit years.
Examples
f_year(as.Date(paste0(1998:2016, '-12-12')))
f_year(c(NA, 1998:2016, 21345))
## Not run:
library(tidyverse)
dat <- data_frame(
year = 1998:2016,
year2 = as.POSIXct(sample(seq_len(1e4), 12), origin = '1970-01-01') +
(365 * 24 * 3600 * seq_len(19)),
val = sample(1:20, length(year), TRUE)
) %>%
mutate(prop = val/sum(val))
dat %>%
ggplot(aes(year, prop)) +
geom_line() +
scale_x_continuous(labels = ff_year(digits = 2), breaks = 1998:2016) +
scale_y_continuous(labels = ff_prop2percent(digits = 0))
dat %>%
ggplot(aes(year2, prop)) +
geom_line() +
scale_x_time(labels = ff_year(digits = 2), breaks = dat$year2) +
scale_y_continuous(labels = ff_prop2percent(digits = 0))
## End(Not run)
[Package numform version 0.7.0 Index]