library(googlesheets4)
library(lubridate)
library(plotly)
Thanksgiving Gantt Chart
rstats
thankyou
Thanksgiving π¦ is right around the corner π β this year we are hosting 17 people π±. If you too are hosting way more than your kitchen normally cooks for, perhaps this will be of interest!
Thanksgiving π¦ is right around the corner π β this year we are hosting 17 people π±.
Ingredients:
π Google Sheet
π¦ googlesheets
π¦ lubridate
π¦ plotly
If you too are hosting way more than your kitchen normally cooks for, perhaps this will be of interest! We decided to make a Google Sheet of the various dishes so we could plot out what will be cooking when.
Packages weβll use
Pull in the data
First we can pull the spreadsheet into R using the googlesheets package.
## Read the sheet into R
<- read_sheet("https://docs.google.com/spreadsheets/d/1k-H3CjkQRQJv7Ni8SA9Ghse8Y-kuKSLVAV4R4w4xXRE/edit?usp=sharing") dishes_df
Clean up a bit π
$start <- as_datetime(dishes_df$start,
dishes_dftz = "America/Chicago")
$finish <- as_datetime(dishes_df$finish,
dishes_dftz = "America/Chicago")
$minutes <- dishes_df$finish - dishes_df$start dishes_df
Letβs pick some lovely turkey-themed colors for our chart π brought to you by colour lovers.
<- c("#487878", "#783030", "#904830", "#A87860", "#D89048")
cols $color <- factor(dishes_df$where, labels = cols)
dishes_df
## Order for the chart
<- dishes_df[order(dishes_df$start,
dishes_df decreasing = TRUE), ]
Make the plot π
This is inspired by a Plotly blog post!
<- plot_ly()
p
for (i in 1:nrow(dishes_df)) {
<- add_lines(p,
p x = c(dishes_df$start[i], dishes_df$finish[i]),
y = c(i, i),
line = list(color = dishes_df$color[i],
width = 20),
hoverinfo = "text",
text = paste("Dish: ",
$dish[i],
dishes_df"<br>",
"Cook time: ",
$minutes[i],
dishes_df"minutes<br>",
"Where: ",
$where[i]),
dishes_dfshowlegend = FALSE
) }
## Add the dish names to the y-axis, remove grid
<- layout(p,
p xaxis = list(showgrid = FALSE),
yaxis = list(showgrid = FALSE,
tickmode = "array",
tickvals = 1:nrow(dishes_df),
ticktext = unique(dishes_df$dish)),
margin = list(l = 200, r = 50, b = 50, t = 50, pad = 4),
plot_bgcolor = "#EBE5E5",
paper_bgcolor = "#EBE5E5",
## add a turkey because why not!
images = list(
list(source = "https://upload.wikimedia.org/wikipedia/commons/c/c9/Twemoji2_1f983.svg",
xref = "paper",
yref = "paper",
x= 0.75,
y= 1,
sizex = 0.25,
sizey = 0.25
) )
) p
Happy feasting! π¦β€οΈ