kmb2

NYC Flights 23

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   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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)
by_origin_dest <- flights %>%
  filter(!is.na(air_time)) %>%
  group_by(origin, dest) %>%
  summarise(
    mean_air_time = mean(air_time, na.rm = TRUE),
    flights = n(),
    .groups = "drop"
  )
top10_dest <- by_origin_dest %>%
  arrange(desc(flights)) %>%
  slice_head(n = 10) %>%
  pull(dest)
by_origin_dest_filtered <- by_origin_dest %>%
  filter(dest %in% top10_dest)
by_origin_dest_filtered <- by_origin_dest_filtered %>%
  left_join(airports, by = c("origin" = "faa")) %>%
  rename(origin_full_name = name) %>%
  left_join(airports, by = c("dest" = "faa")) %>%
  rename(dest_full_name = name) %>%
  select(origin_full_name, dest_full_name, mean_air_time, flights)
ggplot(by_origin_dest_filtered, aes(x = origin_full_name, y = reorder(dest_full_name, mean_air_time), fill = mean_air_time)) +
  geom_tile(color = "#c4216a") +  
  scale_fill_gradient(low = "#1565c0", high = "#ad1457", name = "Avg Air Time (min)") +
  labs(
    title = "Heatmap of Average Air Time to Top 10 Destinations",
    x = "Origin Airport",
    y = "Destination Airport",
    fill = "Avg Air Time (min)",
    caption = "Data Source: transtats.bts.gov"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 12, hjust = 0.5),
    axis.text.x = element_text(angle = 15, size = 6, hjust = 1, color = "black"),
    axis.text.y = element_text(angle = 0, size = 6, hjust = 1, colour = "black") 
  ) + coord_flip()

Visualization Description

This visualization is used to represent the top 10 destinations from the 3 biggest airports in the New York area and the average air time to those destinations. The X-axis has the top 10 destinations and the Y-axis shows the origin airports within New York. Based on the heat map it shows that SFO and LAX have the longest air time from JFK (John F. Kennedy) and EWR (Newark Liberty International). I enjoyed the color palette, and how it was utilized to represent the data set, and I also made sure that the Top 10 Airports were on the X-axis to not clutter the graph in any way.