NYC Flights Assignment

# Loading tidyverse, the streamgraph package, and the flights dataset.
library(streamgraph)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(nycflights23)
Warning: package 'nycflights23' was built under R version 4.6.1
data(flights)
# Cleaning the data to remove NA values, grouping by month and carrier, and creating a new column with the mean delay time and number of flights for each carrier in each month.
mean_flights <- flights %>%
  filter(!is.na(dep_delay)) %>%
  group_by(month, carrier, .groups="drop") %>%
  summarize(mean_delay=mean(dep_delay), n=n())
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by month, carrier, and .groups.
ℹ Output is grouped by month and carrier.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(month, carrier, .groups))` for per-operation grouping
  (`?dplyr::dplyr_by`) instead.
# Creating a date column for months (instead of an integer column) and representing the months with text.
mean_flights <- mean_flights %>%
  mutate(month_date = as.Date(sprintf("2023-%02d-01", month)))

# Making a stream graph with my cleaned flights dataset where carrier is the key, mean delay is the value, and month_date is the date. Adding a legend for carrier names and displaying the abbreviated text in the month_date column on the x-axis. 
mean_delay_stream_graph <- streamgraph(mean_flights, "carrier", "mean_delay", "month_date") %>%
  sg_legend(show = TRUE, label = "carrier") %>%
  sg_axis_x(tick_units = "month_date", tick_format = "%b")
mean_delay_stream_graph
Warning in widget_html(name, package, id = x$id, style = css(width =
validateCssUnit(sizeInfo$width), : streamgraph_html returned an object of class
`list` instead of a `shiny.tag`.
Warning: `bindFillRole()` only works on htmltools::tag() objects (e.g., div(),
p(), etc.), not objects of type 'list'.

Data of flights departing NYC in 2023 from U.S. Bureau of Transportation Statistics