Heatmaps

Load the Libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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)
data(flights)
data(airlines)

flight_carrier_summary <- flights |>
  filter(!is.na(arr_delay)) |> 
  group_by(carrier) |> 
  summarize(
    avg_delay = mean(arr_delay, na.rm = TRUE),
    total_flights = n(),
    .groups = 'drop'
  ) |>
  left_join(airlines, by = "carrier")
p_delay_carrier <- flight_carrier_summary |>
  ggplot(aes(x = name, y = avg_delay, fill = total_flights)) +
  
  geom_col() +
  labs(
    x = "Airline Carrier Name", # **CHANGE:** Updated X-axis label
    y = "Average Arrival Delay (Minutes)",
    title = "Average Arrival Delay by Airline Carrier from NYC (2023)",
    caption = "Data Source: nycflights23 package."
  ) +
  scale_fill_gradient(
    low = "black", high = "white",
    name = "Total Flights\n(Count)"
  ) +
  theme_minimal() +
  
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

p_delay_carrier

Paragraph Explanaton

This bar chart shows the arrival delay for airlines that flew out of New York City in 2013, on average. The x-axis shows the airline carries and their names. The y-axis on the other hand, shows the average delay time in minutes. The bars are colored based on how many total flights each airline had, so blacker bars mean less flights, while whiter bars mean more flights From the chart, you can see that some airlines did a lot better than others when it comes to having only a few delays. For example, Delta and Southwest both had a lot of flights but still had their average delays pretty low, around 10 to 15 minutes. On the other hand, airlines like Frontier and ExpressJet had much longer delays, sometimes over 30 minutes, even though they had less flights if we compare. This shows that having more flights doesn’t always mean more delays. Some airlines are just better at managing their schedules and keeping things running smoothly. Overall, the chart helps compare how well each airline handled arrivals throughout the year using both delay time and flight count.