Flights.HW

Author

Asher Scott

library(nycflights13)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)
library(forcats)

overall_mean_delay <- mean(flights$arr_delay + flights$dep_delay, na.rm = TRUE)

Ovrl_Dly <- flights %>%
  group_by(carrier) %>%
  summarise(mean_delay = mean(arr_delay + dep_delay, na.rm = TRUE)) %>%
  mutate(carrier = fct_reorder(carrier, mean_delay)) %>%
  ggplot(aes(x = carrier, y = mean_delay)) +
  labs(title = "Average Total Delay Times",
       x = "Airlines",
       y = "Minutes") + 
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1), 
        axis.text.y = element_text(face = "bold"),
        plot.title = element_text(hjust = 0.5, size = 25, face = "bold")) +
  geom_hline(yintercept = overall_mean_delay, color = "lightblue", size = 1) +
  geom_segment(aes(xend = carrier, y = overall_mean_delay, yend = mean_delay), color = "violet") +
  geom_point(aes(color = mean_delay), size = 5) +  
  scale_color_gradient(low = "hotpink", high = "yellow")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Ovrl_Dly

```

For this project, I decided to make a visualization that would compare overall delays between the 14 different carriers. The type of visualization that I made was a lollipop chart. The Y axis are the delayed times 10 minutes while the X axis are all of the flight carriers. I use the color gradient to further emphasize the difference in mean delay times with G4 and YX averaging either no delays or even showing up a bit early.By making the blue line the average mean of all arrival and departing delays, I was able to compare which flight carriers were above, and below the average for NYC airports. One aspect of the visualization I would like to highlight is how F9 carriers, also known as frontier airlines, have noticeably the highest total average delay time. If there was one way I would improve this visualization, it would be to change the background to a darker color, and possibly get rid of the lines in the back.