Last active
August 5, 2024 18:05
-
-
Save dsparks/69fe4d454f04129cbaa63abb723432a3 to your computer and use it in GitHub Desktop.
A year on a page calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lubridate) | |
library(forcats) | |
first_date <- "2024-09-01" # Should work well for any date | |
first_date <- ymd(first_date) | |
dates <- tibble(date = first_date + days(-13:372)) %>% | |
mutate(dow = weekdays(date)) | |
dates <- dates %>% | |
mutate(is_sunday = dow == "Sunday", | |
sundays = cumsum(is_sunday)) %>% | |
filter(sundays > 0) | |
dates <- dates %>% | |
add_count(sundays) %>% | |
filter(n == 7) %>% | |
dplyr::select(-n) | |
dates <- dates %>% | |
mutate(dom = day(date), | |
to_print = dom, | |
alt_print = month(date, label = TRUE, abbr = TRUE), | |
to_print = ifelse(dom == 1, as.character(alt_print), as.character(to_print)), | |
to_print = ifelse(alt_print == "Jan" & dom == 1, year(date), to_print), | |
to_print = ifelse(sundays == 1, as.character(dow), to_print), | |
text_col = ifelse(sundays == 1, gray(1/7), gray(6/7)), | |
text_col = ifelse(alt_print == "Jan" & dom == 1, gray(1/7), text_col), | |
border_col = ifelse(dom == 1, gray(1/7), gray(6/7)), | |
border_col = ifelse(sundays == 1, "transparent", border_col), | |
border_lwd = ifelse(dom == 1, 7/7, 1/7), | |
dow = fct_inorder(dow)) | |
# Not currently used | |
caption <- with(dates, paste0(year(first_date), "-", year(first_date)+1)) | |
dates %>% | |
arrange(-dom) %>% | |
ggplot() + | |
aes(x = dow, y = sundays, label = to_print, color = border_col) + | |
geom_text(aes(colour = text_col), | |
family = "mono", fontface = "bold", size = 7) + | |
geom_tile(aes(lwd = border_lwd), | |
fill = "transparent") + | |
scale_colour_identity() + | |
scale_linewidth_identity() + | |
scale_y_reverse(NULL, breaks = NULL, expand = c(0.01, 0.01)) + | |
theme_void() + | |
theme(plot.margin = grid::unit(c(0, 0, 0, 0), "in")) | |
ggsave(plot = last_plot(), h = 17, w = 11, filename = "Year on a page.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This produces a PDF, which looks like this

and is designed to be printed on tabloid (11" × 17") paper. The idea is to just highlight major events, not specific meetings, etc.
You can change the starting date and all of the cosmetic stuff. It's pretty straightforward.