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
dishes_df <- read_sheet("https://docs.google.com/spreadsheets/d/1k-H3CjkQRQJv7Ni8SA9Ghse8Y-kuKSLVAV4R4w4xXRE/edit?usp=sharing")Clean up a bit π
dishes_df$start <- as_datetime(dishes_df$start,
                                          tz = "America/Chicago")
dishes_df$finish <- as_datetime(dishes_df$finish,
                                           tz = "America/Chicago")
dishes_df$minutes <- dishes_df$finish - dishes_df$startLetβs pick some lovely turkey-themed colors for our chart π brought to you by colour lovers.
cols <- c("#487878", "#783030", "#904830", "#A87860", "#D89048")
dishes_df$color  <- factor(dishes_df$where, labels = cols)
## Order for the chart
dishes_df <- dishes_df[order(dishes_df$start,
                             decreasing = TRUE), ]Make the plot π
This is inspired by a Plotly blog post!
p <- plot_ly()
for (i in 1:nrow(dishes_df)) {
  p <- add_lines(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: ",
                              dishes_df$dish[i],
                              "<br>",
                              "Cook time: ",
                              dishes_df$minutes[i],
                              "minutes<br>",
                              "Where: ",
                              dishes_df$where[i]),
                 showlegend = FALSE
  ) 
}
## Add the dish names to the y-axis, remove grid
p <- layout(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
           ) )
)
pHappy feasting! π¦β€οΈ