Description Usage Arguments Value Examples
Format 4 digit integer, date, or POSIXlt formats to 2 or 4 digit years.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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. |
Returns a vector of two or four digit years.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.