knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
A class for week numbers, according to ISO 8601.
Install from GitHub:
remotes::install_github("hmalmedal/weeknumber")
Coercion to the week number class:
library(weeknumber) as_weeknumber(c(-1:1, 51:52, NA)) as_weeknumber("2000-W01") as_weeknumber(as.Date("2000-12-28"))
Make week number object from year and week:
make_weeknumber(2000:2001, 4:5) make_weeknumber(2019:2020, 53)
Get year and week number from an object:
x <- as_weeknumber(c(-1:1, 51:52, NA)) year_week(x)
Print a tibble:
set.seed(0) library(tibble) d <- tibble( x = seq(as_weeknumber("2000-W01"), as_weeknumber("2000-W09")), y = cumsum(rnorm(length(x))) ) print(d)
Plot with week number scale:
library(ggplot2) p <- ggplot(d, aes(x, y)) + geom_line() print(p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.