Skip to content

Instantly share code, notes, and snippets.

@chichacha
Created December 4, 2018 00:12
Show Gist options
  • Save chichacha/82c982dd2c1cdf8cbc1a17d9a3ea7c6d to your computer and use it in GitHub Desktop.
Save chichacha/82c982dd2c1cdf8cbc1a17d9a3ea7c6d to your computer and use it in GitHub Desktop.
4-4-5 Calendar for 2019 - So I know which week is what. Monday as start date.
## Getting Ready for 2019
library(lubridate)
library(tibble)
options("lubridate.week.start"=1) ## 1 sets to Monday
calendar <- tibble(
date = seq.Date(from=ymd("2018-12-31"),to=ymd("2019-12-31"), by="day")
)
calendar <-
calendar %>% mutate(wkdy = wday(date,label=T),
week_start=floor_date(date,"week"),
weeknum = dense_rank(week_start),
mo = month(date,label=T)) %>%
mutate(fiscal_mo = cut(weeknum,breaks=c(0,4,8,13,17,21,26,30,34,39,43,47,52),
ordered_result=T, labels=c(month.abb)))
calendar %>%
group_by(weeknum,fiscal_mo,week_start) %>%
summarise(week_end=max(date)) %>%
mutate(week_start=format(week_start,"%Y %B %e %A"),
week_end = format(week_end,"%Y %B %e %A")) %>%
rename(WeekNumber=weeknum, FiscalMonth=fiscal_mo, WeekStart=week_start, WeekEnd=week_end) %>%
knitr::kable("markdown")
library(ggthemes)
calendar %>% filter(!(is.na(fiscal_mo))) %>%
ggplot(aes(x=wkdy,y=weeknum)) +
geom_tile(aes(fill=mo), color="white") +
geom_text(aes(label=format(date,"%e")), color="white", family="Roboto Condensed") +
facet_wrap(~fiscal_mo, scales="free",ncol=3) +
scale_y_reverse() +
theme_ipsum_rc() +
scale_fill_tableau(palette="Classic Cyclic", guide="none") +
labs(title="2019 Calendar")
ggsave(file="output/2019_Calendar.pdf", width=16, height=9, device=cairo_pdf)
@chichacha
Copy link
Author

2019_calendar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment