knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  comment = "#>",
  fig.path = "man/figures/README-",
  fig.width = 10,
  fig.height = 8,
  fig.retina = 2,
  out.width = "100%"
)

showtext::showtext_auto()
sysfonts::font_add_google("PT Sans")
sysfonts::font_add_google("PT Sans Narrow")

ggweekly

The goal of ggweekly is to easily create custom weekly planners with ggplot2.

Installation

You can install ggweekly from GitHub with devtools

devtools::install_github("gadenbuie/ggweekly")

Example

This is a basic example which shows you how to create a weekly planner covering April, May, and June of 2019.

library(ggweekly)
ggweek_planner(
  start_day = "2019-04-01", 
  end_day = "2019-06-30", 
)

You can also create traditional calendars as well.

ggweek_planner(
  start_day = "2019-04-01", 
  end_day = "2019-06-30", 
  show_month_boundaries = FALSE, 
  show_month_start_day = FALSE,
  week_start = "isoweek",
  week_start_label = "week"
) + 
  ggplot2::ggtitle("2019") +
  ggplot2::facet_wrap(~ month, scales = 'free')

Use week_start to choose between weeks that start on Monday ("isoweek") or weeks that start on Sunday ("epiweek"). You can also set (or remove) the weekend color fill with weekend_fill.

ggweek_planner(
  start_day = "2019-04-01", 
  end_day = "2019-06-30", 
  show_month_boundaries = FALSE, 
  show_month_start_day = FALSE,
  week_start = "epiweek",
  week_start_label = "week",
  weekend_fill = "#FFFFFF"
) + 
  ggplot2::ggtitle("2019") +
  ggplot2::facet_wrap(~ month, scales = 'free')

Project Planning

Create a tibble of days to highlight and pass into highlight_days.

project_days <- dplyr::tribble(
          ~day,             ~label,    ~color,     ~fill,
  "2019-07-02", "Project Kick Off", "#02307a", "#02307a",
  "2019-07-12",          "LOI Due", "#02307a", "#02307a",
  "2019-07-26",      "First Draft", "#02307a", "#02307a",
  "2019-08-05",        "Work week", "#bf006c", "#bf006c",
  "2019-08-06",                 NA,        NA, "#bf006c",
  "2019-08-07",                 NA,        NA, "#bf006c",
  "2019-08-08",                 NA,        NA, "#bf006c",
  "2019-08-09",                 NA,        NA, "#bf006c",
  "2019-08-23", "Final Submission", "#02307a", "#02307a"
)


ggweek_planner(
  start_day = "2019-07-01",
  highlight_days = project_days
) +
  ggplot2::ggtitle("A Very Important Project")

Printable Calendars

Here's a printable calendar of 8 week time periods for 2019 and 2020:

The code chunk below shows how this PDF was created and can be adjusted as needed. I included margins to the left and below the calendar for extra notes.

start_date <- lubridate::floor_date(lubridate::ymd("2019-01-01"), "week", week_start = 1)
end_date <- lubridate::ceiling_date(lubridate::ymd("2019-12-31"), "week", week_start = 1) - 
  lubridate::days(1)
week_dates <- seq(start_date, end_date, by = "56 day")

pdf(here::here("printable", "2019-weekly-planner.pdf"), width = 8.5, height = 11)
for (idx_week in seq_along(week_dates)) {
  gcal <- ggweek_planner(start_day = week_dates[idx_week]) +
    ggplot2::theme(plot.margin = ggplot2::margin(1, 2, 3, 0.5, "in")) +
    ggplot2::ggtitle(paste(
      strftime(week_dates[idx_week], "%B %e, %Y"),
      strftime(week_dates[idx_week] + 55, "%B %e, %Y"),
      sep = " — "
    ))
  print(gcal)
}
dev.off()
start_date <- lubridate::floor_date(lubridate::ymd("2020-01-01"), "week", week_start = 1)
end_date <- lubridate::ceiling_date(lubridate::ymd("2020-12-31"), "week", week_start = 1) - 
  lubridate::days(1)
week_dates <- seq(start_date, end_date, by = "56 day")

pdf(here::here("printable", "2020-weekly-planner.pdf"), width = 8.5, height = 11)
for (idx_week in seq_along(week_dates)) {
  gcal <- ggweek_planner(start_day = week_dates[idx_week]) +
    ggplot2::theme(plot.margin = ggplot2::margin(1, 2, 3, 0.5, "in")) +
    ggplot2::ggtitle(paste(
      strftime(week_dates[idx_week], "%B %e, %Y"),
      strftime(week_dates[idx_week] + 55, "%B %e, %Y"),
      sep = " — "
    ))
  print(gcal)
}
dev.off()

And here are fullpage yearly calendars for 2019 and 2020.

g2019 <- ggweek_planner(
  start_day = "2019-01-01", 
  end_day = "2019-12-31", 
  show_day_numbers = TRUE, 
  show_month_boundaries = FALSE, 
  show_month_start_day = FALSE,
  week_start_label = "week"
) + 
  ggplot2::ggtitle("2019") +
  ggplot2::facet_wrap(~ month, scales = 'free')

ggplot2::ggsave(
  file = here::here("printable", "2019-full-year.pdf"),
  plot = g2019,
  width = 11, height = 8.5
)
g2019 <- ggweek_planner(
  start_day = "2020-01-01", 
  end_day = "2020-12-31", 
  show_day_numbers = TRUE, 
  show_month_boundaries = FALSE, 
  show_month_start_day = FALSE,
  week_start_label = "week"
) + 
  ggplot2::ggtitle("2020") +
  ggplot2::facet_wrap(~ month, scales = 'free')

ggplot2::ggsave(
  file = here::here("printable", "2020-full-year.pdf"),
  plot = g2019,
  width = 11, height = 8.5
)

Please note that the 'ggweekly' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



gadenbuie/ggweekly documentation built on Sept. 15, 2020, 2:23 a.m.