Title: | Create static (and interactive) overview calendars using ggplot2 |
---|---|
Description: | Creates tile-based calendar layouts using ggplot2 facets and tiles. Calculates calendar layout positioning variables, and generates customisable ggplot2 calendars for specified time periods and calendar units. |
Authors: | Cynthia A. Huang [aut, cre] |
Maintainer: | Cynthia A. Huang <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2025-03-07 04:49:50 UTC |
Source: | https://github.com/cynthiahqy/ggtilecal |
Helper function for calculating calendar layout variables.
calc_calendar_vars( .data, date_col, locale = Sys.getlocale("LC_TIME"), week_start = 1 )
calc_calendar_vars( .data, date_col, locale = Sys.getlocale("LC_TIME"), week_start = 1 )
.data |
tibble or data frame containing dates to be plotted in calendar layout |
date_col |
column containing calendar unit dates |
locale |
locale to use for day names. Default to current locale. |
week_start |
day on which week starts following ISO conventions: 1 means Monday
and 7 means Sunday (default). When |
Tibble with additional calendar layout variables:
TC_year
, TC_month_label
, TC_mday
,
TC_wday_label
, TC_wday
, TC_month_week
,
TC_is_weekend
make_empty_month_days(c("2024-01-01", "2024-02-01")) |> calc_calendar_vars(unit_date)
make_empty_month_days(c("2024-01-01", "2024-02-01")) |> calc_calendar_vars(unit_date)
A set of 5 demo events generated by ChatGPT 3.5 on 13 Apr, 2024. The following field descriptions were also generated in the same session.
demo_events_gpt
demo_events_gpt
A data frame with 5 (event) rows and 7 columns:
Unique identifier for the event.
Start date of the event.
End date of the event.
Duration of the event.
Title or name of the event.
Description of the event.
Emoji representing the event theme or type.
URL link to the event's website or page.
https://chat.openai.com/share/c68b7a82-5378-45c8-bf41-7fa134f0b74a
A set of 10 demo events where Events 6,7,8 and 9 overlap, with placeholder details generated using the zoo and ipsum.
demo_events_overlap
demo_events_overlap
A data frame with 10 (event) rows and 6 columns:
Unique identifier for the event.
Plaeholder title for the event
Start date of the event.
End date of the event.
Duration of the event in days.
Emoji representing the event theme or type.
Loreum Ipsum placeholder details of the event.
Package Authors
Helper function for filling out event table with any missing calendar units.
fill_missing_units( .events_long, date_col, adjust_months = NULL, cal_unit = "day" )
fill_missing_units( .events_long, date_col, adjust_months = NULL, cal_unit = "day" )
.events_long |
long format calendar event data |
date_col |
column containing calendar unit dates |
adjust_months |
how many months to add before and after |
cal_unit |
increment of calendar sequence passed to |
tibble
demo_events_gpt |> reframe_events(startDate, endDate) |> fill_missing_units(unit_date)
demo_events_gpt |> reframe_events(startDate, endDate) |> fill_missing_units(unit_date)
Generates calendar with monthly facets by:
Padding event list with any missing days via fill_missing_units()
Calculating variables for calendar layout via calc_calendar_vars()
Returning a ggplot object as per Details.
gg_facet_wrap_months( .events_long, date_col, locale = NULL, week_start = NULL, nrow = NULL, ncol = NULL, .geom = list(geom_tile(color = "grey70", fill = "transparent"), geom_text(nudge_y = 0.25)), .scale_coord = list(scale_y_reverse(), scale_x_discrete(position = "top"), coord_fixed(expand = TRUE)), .theme = list(theme_bw_tilecal()), .other = list() )
gg_facet_wrap_months( .events_long, date_col, locale = NULL, week_start = NULL, nrow = NULL, ncol = NULL, .geom = list(geom_tile(color = "grey70", fill = "transparent"), geom_text(nudge_y = 0.25)), .scale_coord = list(scale_y_reverse(), scale_x_discrete(position = "top"), coord_fixed(expand = TRUE)), .theme = list(theme_bw_tilecal()), .other = list() )
.events_long |
long format calendar event data |
date_col |
column containing calendar unit dates |
locale |
locale to use for day names. Default to current locale. |
week_start |
day on which week starts following ISO conventions: 1 means Monday
and 7 means Sunday (default). When |
nrow , ncol
|
Number of rows and columns. |
.geom , .scale_coord , .theme , .other
|
Customisable lists of ggplot2 components to add to the plot.
An empty |
Returns a ggplot with the following fixed components using calculated layout variables:
aes()
mapping:
x
is day of week,
y
is week in month,
label
is day of month
facet_wrap()
by month
labs()
to remove axis labels for calculated layout variables
and default customisable components:
geom_tile()
, geom_text()
to label each day which inherit calculated variables
scale_y_reverse()
to order day in month correctly
scale_x_discrete()
to position weekday labels
coord_fixed()
to square each tile
theme_bw_tilecal()
to apply sensible theme defaults
To modify components alter the .geom
and .scale_coord
,
which inherit the calculate layout mapping by default
(via the ggplot2 inherit.aes
argument).
To additional components use the ggplot +
function as normal,
or pass components to the .other
argument.
This can be used to add interactive geoms (e.g. from ggiraph
)
To modify the theme, use the ggplot +
function as normal,
or add additional elements to the list in .theme
.
To remove any of the optional components, set the argument to any empty list()
ggplot
library(dplyr) library(ggplot2) demo_events_gpt |> reframe_events(startDate, endDate) |> group_by(unit_date) |> slice_min(order_by = duration) |> gg_facet_wrap_months(unit_date) + geom_text(aes(label = event_emoji), nudge_y = -0.25, na.rm = TRUE)
library(dplyr) library(ggplot2) demo_events_gpt |> reframe_events(startDate, endDate) |> group_by(unit_date) |> slice_min(order_by = duration) |> gg_facet_wrap_months(unit_date) + geom_text(aes(label = event_emoji), nudge_y = -0.25, na.rm = TRUE)
Creates empty day units using make_empty_units()
that span the months
encompassing cal_range
with the option to adjust the number of months
either side of cal_range
make_empty_month_days( month_range, dates_to = "unit_date", adjust_months = c(-0, 0) )
make_empty_month_days( month_range, dates_to = "unit_date", adjust_months = c(-0, 0) )
month_range |
vector of dates. |
dates_to |
string name for column to output calendar unit dates |
adjust_months |
how many months to add before and after |
tibble with one row per day in specified months
make_empty_month_days(c("2024-03-05", "2024-04-15"))
make_empty_month_days(c("2024-03-05", "2024-04-15"))
Make empty sequence of calendar units between specified date range
make_empty_units(cal_range, dates_to = "unit_date", cal_unit = "day")
make_empty_units(cal_range, dates_to = "unit_date", cal_unit = "day")
cal_range |
|
dates_to |
string name for column to output calendar unit dates |
cal_unit |
increment of calendar sequence passed to |
tibble
make_empty_units(c("2024-03-05", "2024-04-15"))
make_empty_units(c("2024-03-05", "2024-04-15"))
reframe_events( .data, event_start, event_end, id_cols = NULL, dates_to = "unit_date", cal_unit = "day" )
reframe_events( .data, event_start, event_end, id_cols = NULL, dates_to = "unit_date", cal_unit = "day" )
.data |
A data frame or tibble containing event details |
event_start |
column containing event start date |
event_end |
column containing event end date |
id_cols |
(optional) set of columns that uniquely identify each observation.
Ignored if |
dates_to |
string name for column to output calendar unit dates |
cal_unit |
increment of calendar sequence passed to |
Convert rows of events to sequence of calendar units for plotting.
Duplicates all columns except for event_start
and event_date
.
Requires a unique id key for each event.
This is a thin wrapper around dplyr::reframe()
that expands
each uniquely identified event in .data
to a sequence of datetimes defined
by the start
, end
and the interval cal_unit
.
See return value of reframe
event <- data.frame( id = 1, start = as.Date("2024-01-05"), end = as.Date("2024-01-10") ) reframe_events(event, start, end) demo_events_gpt |> reframe_events(startDate, endDate)
event <- data.frame( id = 1, start = as.Date("2024-01-05"), end = as.Date("2024-01-10") ) reframe_events(event, start, end) demo_events_gpt |> reframe_events(startDate, endDate)
ggplot2::theme_bw()
for calendar layoutsA modified version of ggplot2::theme_bw()
for calendar layouts
theme_bw_tilecal( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22 )
theme_bw_tilecal( base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22 )
base_size |
base font size, given in pts. |
base_family |
base font family |
base_line_size |
base size for line elements |
base_rect_size |
base size for rect elements |