# NOT RUN {
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))
# }
Run the code above in your browser using DataLab