Skip to content

Instantly share code, notes, and snippets.

@chichacha
Last active June 15, 2018 18:12
Show Gist options
  • Save chichacha/fd08926ed7545009c3befc5086a69345 to your computer and use it in GitHub Desktop.
Save chichacha/fd08926ed7545009c3befc5086a69345 to your computer and use it in GitHub Desktop.
Calendar For Current Year (Monday as Start Date)
## 2018 Calendar
library(tidyverse)
library(hrbrthemes)
library(scales)
library(lubridate)
library(ggthemes)
## Set Global Option for Lubridate
options("lubridate.week.start"=1) ## 1 sets to Monday
Sys.setenv(TZ = "America/Vancouver")
calendar.tbl <- tibble(
date = seq.Date(from=floor_date(today(),"year"), to=ceiling_date(today(),"year")-1, by="day"),
wk = week(date),
mo = month(date, label=T),
day = day(date),
wday = wday(date, label=T),
week.start.day = floor_date(date,"week"),
mo_alt = month(week.start.day,label=T, abbr=F),
mo.445 = dense_rank(cut(wk,c(0,4,8,13,17,21,26,30,34,39,43,47,52,56))),
qt.445 = quarter(mo.445)
)
ggplot(calendar.tbl, aes(x=wday, y=wk)) +
geom_tile(color="white", aes(fill=factor(mo.445))) +
geom_text(aes(label=format(date,"%e")), family="Roboto Condensed", color="white") +
scale_y_reverse(breaks=c(1:53)) +
facet_wrap(~mo, scales="free", ncol=3) +
theme_ipsum_rc() +
labs(title="2018 Calendar", subtitle="With Week Number Listed") +
scale_fill_tableau("cyclic", name="445 Month")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment