Comprehensive data entries from New York City map the arrival and departure of flights in and out of the city in 2013. A lot of flights took place in New York airports this year (336,776 Flights, to be exact!), and fliers got to choose between 16 different carriers. The data set we’re using also contains information on the distance each flight traveled, as well as the delay in arrival (how close the flight was to anticipated arrival time).
Assessing flight travel time seems tricky. There are many variables to manage: the weather conditions, pre-flight matainence, and any number of things which could go wrong before and during flight. In particular, a point of interest for us was how airports handled their arrival time predictions. Is this information generally accurate? Do different months of the year, with their own seasonal weather conditions, lead to less accurate arrival time predictions? Does distance impact prediction abilities for flight arrival time?
#Assigning important variables, loading relevant packages
library(tidyverse)
library(ggthemes)
library(nycflights13)
Fly <- nycflights13::flights
Total_Delay <- Fly$arr_delay - Fly$dep_delay
Fly_time <- Fly$hour*60 + Fly$minute
Fly$Total_Delay <- Total_Delay
Fly$Late_Flights <- Fly$Total_Delay>0
Late_Flights <- Fly$Total_Delay>0
#Code for the histogram data graphic
Fly_Hist <-
ggplot(Fly, aes(x=Total_Delay)) +
geom_histogram(color="orange", aes(fill=Late_Flights))+
facet_wrap(~month)+
labs(x= "Total Delay Time of Flight (in Mins)",
y="Number of Flights",
title = "Total Delay Time for Flights To & From NYC")+
geom_vline(xintercept =0, color="red", size=.2)
Fly_Hist
In this histogram, the x-axis takes account of the total delay time of flights, measured in minutes. A negative total delay would demonstrate that the flight took less time that the predicted arrival and departure times inferred. A positive total delay would mean the flight took longer than the predicted duration.
The x-intercept is marked with a red line to make this comparison clear. This clarity is reinforced by a color scheme which fills the histogram bins with red at every data point in which the total delay was less zero (once again, flights that took less time than predicted) and fills them with blue at every data point in which the total delay was greater than 0.
Lastly, this information is faceted by month. This serves two functions: it breaks our information into 12 different graphs to demonstrate specific variations, and it also allows us to draw comparisons in seasons.
We can learn from this histogram that flight predictions to and from New York City airports tend to overestimate flight duration more often than it underestimates flight duration.
As an aside, we can also learn that airport flight predictions are generally fairly good at controlling for weather and seasonal variations.
This histogram is the clearest representation of this information because it simplifies the information very cleanly. For one, the histogram allows us to focus on one quantitative variable (the y-axis is a count of units, or flights in this case) and therefore simplifies the information. Secondly, it is particularly useful for the large size of our data set by simplifying hundreds of thousands of data points into simple, defined rectangles.