NYC Flights Homework

Author

Ashley Ramirez

Average departure delays by airline in NYC 2013.

Load Tidyvers

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.3     ✔ tidyr     1.3.1
✔ purrr     1.0.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(nycflights13)

Filter the information to find the average delay between airlines

avg_delay <- flights %>%
  group_by(carrier) %>%
  summarize(avg_delay = mean(dep_delay, na.rm = TRUE)) %>%
  arrange(desc(avg_delay))

Plot

ggplot(avg_delay, aes(x = reorder(carrier, avg_delay), y = avg_delay, fill = carrier)) +
  geom_bar(stat = "identity", color = "black") +
  scale_fill_manual(values = c(
    "9E" = "#EECF6D", "AA" = "#D5AC4E", "AS" = "#8B6220", "B6" = "#720E07",
    "DL" = "#45050C", "EV" = "#FF6F59", "F9" = "#9F2042", "FL" = "#2DC2BD",
    "HA" = "#211103", "MQ" = "#FCDFA6", "OO" = "#8e44ad", "UA" = "#4C4C9D",
    "US" = "#677DB7", "VX" = "#9CA3DB", "WN" = "#6D3B47", "YV" = "#12664F"
  )) +
  labs(
    title = "Average Departure Delay by Airline",
    x = "Airline",
    y = "Average Departure Delay (minutes)",
    caption = "Data Source: nycflights13"
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "none"  # This line removes the legend
  )

Description

This bar graph represents the average of departure delay in minutes for each airline carrier using the NYCflights13 dataset. The x-axis shows the different airlines, and the y-axis gives the average time taken at the time of departure delay in minutes. Each bar is colored differently by their own hex code for easy distinction between airlines. The outline of the bars is black to form a limit and to help with separating the airlines. This was done to aid readability such that the airline names could be read comfortably by rotating the x-axis labels.

This visualization is useful because it helps in the identification of which airlines tend to have higher and lower average departure delays. Airlines with longer average delays can be spotted in one fell swoop, which could also point out possible problems in their operations or scheduling. Conversely, those airlines with shorter delays are perceived as more reliable. The graph will be useful for passengers while deciding on which airlines to take when comparing several airlines based on their punctuality and airline companies for analysis and performance improvement. This bar graph provides a detailed comparison of the delay of each airline’s departure, emphasizing the difference in punctuality among carriers.