In this lab we explore flights, specifically a random sample of domestic flights that departed from the three major New York City airports in 2013.
We will generate simple graphical and numerical summaries of data on these flights and explore delay times. You can find the instructions for this lab here
# 1. load the library "tidyverse"
library(tidyverse)
# 2. use the read_csv file to read the dataset
nycflights <- read_csv("data/nycflights.csv")Question: Experiment with different binwidths to
adjust your histogram in a way that will show its important features.
You may also want to try using the + scale_x_log10(). What
features are revealed now that were obscured in the original
histogram?
## Warning in self$trans$transform(x): NaNs produced
## Warning: Transformation introduced infinite values in continuous x-axis
## Warning: Removed 19936 rows containing non-finite values (`stat_bin()`).
Answer: [Replace this with your answer]
Question: Create a new data frame that includes
flights headed to SFO in February, and save this data frame as
sfo_feb_flights. How many flights meet these criteria?
Answer: [The number of flights going from NY to SF in February is 68]
Question: Describe the distribution of the arrival delays of flights headed to SFO in February, using an appropriate histogram and summary statistics.
Answer: [Replace this with your answer]
Question: Calculate the median and interquartile
range for arr_delays of flights in in the
sfo_feb_flights data frame, grouped by carrier. Which
carrier has the most variable arrival delays?
Answer: [Replace this with your answer]
Question: Create a list of origin
airports and their rate of on-time-departure. Then visualize the
distribution of on-time-departure rate across the three airports using a
segmented bar plot (see below). If you could select an airport based on
on time departure percentage, which NYC airport would you choose to fly
out of? Hint: For the segmented bar plot, will need to
map the aesthetic arguments as follows:
x = origin, fill = dep_type and a geom_bar()
layer. Create three plots, one with geom_bar() layer, one
with geom_bar(position = "fill") and the third with
geom_bar(position = "dodge"). Explain the difference
between the three results.
Question: Mutate the data frame so that it includes
a new variable that contains the average speed, avg_speed
traveled by the plane for each flight (in mph, or if you are brave, in
km/h). Now make a scatter plot of distance
vs. avg_speed. Think carefully which of the two variables
is the predictor (on the x-axis) and which is the outcome
variable (on the y-axis) and explain why you made this
choice. Describe the relationship between average speed and
distance.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Answer: [Replace this with your answer]
Question: Replicate the following plot and determine what is the cutoff point for the latest departure delay where you can still have a chance to arrive at your destination on time.
Answer: [Replace this with your answer]