NYC Flights Homework

Author

T Manha

Load in the Data

library(tidyverse)
library(nycflights23)
library(RColorBrewer)
library(dplyr)
library(lubridate)
library(ggalluvial)

data(flights)

Type of Plot

For this assignment I will create a heat tree map that will determine which airlines were the most popular to take by month

Data

Grouping the data by months

monthly_flights <- flights %>%
  group_by(month, carrier) %>%
  summarise(total_flights = n(), .groups = 'drop') %>%
  arrange(month, desc(total_flights))

Grouping to top ten airlines per month

top_airlines <- monthly_flights %>%
  group_by(month) %>%
  top_n(10, total_flights) %>%
  ungroup()

Creating the alluvial heat map

ggplot(top_airlines, aes(x = month, y = total_flights, alluvium = carrier)) + 
  theme_bw() +
  geom_alluvium(aes(fill = carrier), 
                color = "white",
                width = .1, 
                alpha = .8,
                decreasing = FALSE) +
  scale_fill_brewer(palette = "Spectral") + 
  labs(title = "Top 10 Airlines by Number of Flights Each Month in NYC (2023)",
       y = "Number of Flights", 
       fill = "Airline",
       caption = "Data Source: NYC Flights 2023") +
  scale_x_discrete(limits = unique(top_airlines$month))
Warning in scale_x_discrete(limits = unique(top_airlines$month)): Continuous limits supplied to discrete scale.
ℹ Did you mean `limits = factor(...)` or `scale_*_continuous()`?

Essay

This alluvial heat map visualizes the top ten airlines by number of flights each month in NYC for 2023, showcasing trends in airline activity over the year. This alluvial heat map visualizes the top ten airlines by number of flights each month in NYC for 2023, showcasing trends in airline activity over the year. The top three airlines throughout the year appear to be Republic (YX), United (UA), and with JetBlue (B6) and Delta (DL) switching places around halfway through August. Republic and United also switch places but later on in the year, around halfway through November. This is also around the time when holidays start to pick up so it leaves me wondering if the residents of New York see United as a more reliable/safe airline than Republic despite preferring the latter for the majority of the year. It also may be connected to the pricing of the tickets by airline. That’s the one thing I wished this data set provided, I would like to see the effect that prices have on airline preference throughout the year.