# Summarize the data to get the average departure delay for each carriercarrier_delay <- flights %>%group_by(carrier) %>%summarize(avg_dep_delay =mean(dep_delay, na.rm =TRUE)) %>%arrange(desc(avg_dep_delay))# Create a bar plot of the average departure delay by carrierggplot(carrier_delay, aes(x =reorder(carrier, -avg_dep_delay), y = avg_dep_delay, fill = carrier)) +geom_bar(stat ="identity") +scale_fill_brewer(palette ="Set3") +labs(title ="Average Departure Delay by Carrier",x ="Carrier",y ="Average Departure Delay (minutes)",caption ="Source: nycflights23 dataset" ) +theme_minimal() +theme(legend.position ="bottom", legend.title =element_blank())
Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Set3 is 12
Returning the palette you asked for with that many colors
The bar graph illustrates the average departure delay, measured in minutes, for different airlines operating flights in the NYC area. The data is sourced from the nycflights23 dataset, which includes information about flights departing from New York City airports. Each bar represents a different airline carrier, sorted by the average departure delay from highest to lowest. The length of each bar indicates the average delay experienced by flights operated by that carrier. Airlines with longer bars experienced greater average departure delays. Notably, some carriers consistently show higher average delays compared to others, which can impact passenger travel experiences and overall airline performance metrics. This visualization allows for a quick comparison of airlines based on their average departure delay times, aiding in understanding operational efficiencies and potential areas for improvement within the airline industry.
Getting deeper into the data: I want to know carrier efficiencies by monthly averages.
# Summarize the data to get the monthly average departure delay for each carriermonthly_carrier_delay <- flights %>%mutate(month =month(time_hour, label =TRUE)) %>%group_by(month, carrier) %>%summarise(avg_dep_delay =mean(dep_delay, na.rm =TRUE)) %>%arrange(month)
`summarise()` has grouped output by 'month'. You can override using the
`.groups` argument.
# Create a line plot of the monthly average departure delay by carrierggplot(monthly_carrier_delay, aes(x = month, y = avg_dep_delay, color = carrier, group = carrier)) +geom_line() +geom_point() +labs(title ="Monthly average departure delays by carrier",x ="Month",y ="Average Departure Delay (minutes)",caption ="Source: nycflights13 dataset") +scale_color_manual(values = scales::hue_pal()(length(unique(monthly_carrier_delay$carrier)))) +theme_minimal() +theme(legend.position ="bottom", legend.title =element_blank())
The visualization illustrates the monthly average departure delays for major airlines operating within the NYC area, based on data from the nycflights23 dataset. Each line in the plot represents a different carrier, distinguished by colors such as blue for Delta and red for United. By examining the plot, one can observe notable patterns: for instance, Delta consistently maintains lower average delays compared to United, especially evident during peak travel months like July and December. Conversely, United experiences more variability in delays, peaking notably in January and September. This visualization not only facilitates direct comparisons between carriers but also highlights seasonal trends that may influence travel planning and operational strategies for airlines and travelers alike.