library(nycflights23)
library(tidyverse)
data(flights)
data(airlines)NYC Flights Histogram 2023
Use the dataset NYCFlights23
Introduction
For this assignment, I created for myself a histogram after I had then used up all of the nycflights23 dataset. I hoped to see flight arrival times off their schedule. Therefore I created a graph showing how arrival delays for all 2023 NYC flights spread. This shows just how big it is that delays are less common than are small ones.
Data Prep
flights_clean <- flights %>%
filter(!is.na(arr_delay), arr_delay > -50, arr_delay < 300) %>%
left_join(airlines, by = "carrier")Histogram of Arrival Delays
# Create histogram with full airline names
ggplot(flights_clean, aes(x = arr_delay, fill = name)) +
geom_histogram(bins = 40, alpha = 0.8, position = "identity") +
labs(
title = "Distribution of Arrival Delays for NYC Flights (2023)",
x = "Arrival Delay (minutes)",
y = "Number of Flights",
caption = "Data Source: nycflights23 package") +
scale_fill_brewer(palette = "Set2", name = "Airline") +
theme_minimal() +
theme(
plot.title = element_text(size = 14, face = "bold"),
legend.position = "right")Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Brief Paragraph
This histogram shows the overall pattern of flight arrival delays in New York City during 2023. I used the filter() command from dlpyr to rake out any missing values and very extreme delays, so the results would be clearer and easier to interpret. I included airlines to get their full names, each bar represents the number of flights that fall within a certain delay range, while each of the colors represent different airline carriers. Most flights arrived close to their scheduled times, with many falling between 0 and 20 minutes late. There is also a noticeable number of flights that arrived early, shown by the negative delay values on the left side of the graph. A few airlines seem to have more delays than others, which can be seen by how their colors look more often in the higher delay ranges. Overall, this histogram helps show how delays are distributed across all NYC flights in 2023 and gives a better idea of what kinds of delays are most common. It’s a simple but useful way to visualize flight performance throughout the year.