NYC Flights Homework

Author

Ameer Adegun

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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)
flights_nona <- flights |>
  filter(!is.na(arr_delay) & !is.na(dep_delay))
delayed_summary <- flights_nona |>
  group_by(carrier) |>
  summarise(avg_arr_delay = mean(arr_delay),
            avg_dep_delay = mean(dep_delay))
ggplot(delayed_summary, aes(x = avg_dep_delay, y = avg_arr_delay)) +
  geom_point(size = 3, alpha = .7, color = "pink") +
  geom_smooth(se = FALSE, color = "orange") +
  theme_minimal() +
  labs(
    x = "Average Departure Delay (minutes)",
    y = "Average Arrival Delay (minutes)",
    title = "Relationship Between Departure and Arrival Delays",
    caption = "Source: FAA Aircraft Registry and nycflights23 dataset"
  )
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The visualization I created represents the relationship between delayed departures and delayed arrival for a flight leaving New York. The data I used comes from the NYCflights23 dataset. The type of graph I chose for this specific assignment was a scatterplot because it is the one I’ve become the most accustomed to. I started by filtering out all blank or NA values from the arrival delay or departure delay. From there, I grouped all flights by the type of Airline, while calculating the average arrival delay and average departure delay. The scatterplot displays the average departure delay on the x-axis and the average arrival delay on the y-axis. One aspect I really like from the visualization is the relationship between delayed departure and arrival delay, as I didn’t think the two variables would have a positive relationship. This means that when a flight arrives late, it affects the flight’s schedule and makes it harder for the flight to arrive on time at a destination.