library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ 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)
avg_delay <- flights %>%
  group_by(carrier) %>%
  summarize(mean_dep_delay = mean(dep_delay, na.rm = TRUE)) %>%
  arrange(desc(mean_dep_delay))
ggplot(avg_delay, aes(x = reorder(carrier, mean_dep_delay), 
                      y = mean_dep_delay, 
                      fill = mean_dep_delay)) +
  geom_col() +
  coord_flip() +
  scale_fill_gradient(low = "skyblue", high = "darkred") +
  labs(title = "Average Departure Delay by Airline - NYC Flights 2013",
       x = "Airline Carrier",
       y = "Average Departure Delay (minutes)",
       fill = "Delay (minutes)",
       caption = "Data source: nycflights23 package (flights dataset)") +
  theme_minimal()

For my data visualization, I used a bar graph and chose to show the airline carriers and their respective mean departure delay. To create the variable for average delay, I used the dplyr commands group_by() and summarize() to calculate the mean departure delay per carrier, and then used arrange() to sort the results. The graph uses both blue and red to show how extreme the delays are with the blueish color being from around 0-15 minutes and reddish being from 15 and on, this makes it much easier to identify which carriers are more likely to be more late and which are closer to being on time. Some of the better carriers are G4, YX, and 9E and the worse ones being F9, B6, and HA.This data visualization could be helpful for someone looking to travel from NYC because it could maybe offer insights on the given carriers and influence which carrier they choose when flying out of NYC.