Lab 3: Flights I

The Data

Believe it or not, detailed information about flights is public record! The Bureau of Transportation Statistics, a federal agency, collects and hosts this data for public download. The data we are working with this week (and next) consists of all flights that left OAK and SFO during the 2020 calendar year. Here are some interesting points.:

  • If you flew in 2020 out of either of these airports, you can find out the exact plane you were on and exactly when it departed and landed.

  • 2020 saw the larger, global onset of the COVID-19 pandemic, so many flights were grounded at the start of the pandemic. Might we see evidence of this in the data?

We will be answering questions like these (and more) in this lab. The flights data frame is located in the stat20data package. Once you’ve loaded in this package, you can use the dataframe right away, but see it in the top-right panel with your other variables (the “environment” pane), run command data(flights).

Question 1

Part A

What is the unit of observation in the flights data frame?

Part B

What are the dimensions of the flights data frame, in rows and columns?

Question 2

Part A

List three variables in the flights data frame that are categorical.

Part B

List three variables in the flights data frame that are numerical.

Part C

Are there any variables which are recorded using numbers but should be treated categorically? Write them here.

Part D

Are there any variables which could reasonably be interpreted as either categorical or numerical? Write them here.

Question 3

Look at some of the values in the dep_time column. What is your best guess for how these encode times? Said another way, what would a value of 1517 mean?

Question 4

Part A

Write ggplot2 code to create a bar chart that shows the distribution by month of all the flights leaving the Bay Area (from SFO and OAK airports together).

Part B

Do you see any sign of an effect of the COVID-19 pandemic on flight patterns? Describe in a sentence or two.

Question 5

Part A

Write ggplot2 code to create a histogram showing the distribution of departure delays for all flights.

Part B

Using the lims() ggplot layer, set the limits of the x-axis to focus on where most of the data lie. This also means some data will be (literally) off the chart. There’s some subjective judgment to this (no one “right” answer), but your goal is to allow the viewer to see the shape of the distribution clearly. Write a sentence or two describing what you did and why.

Part C

Add a text annotation to your plot that explains the meaning of a negative departure delay.

Part D

Describe the shape and modality of the distribution in 1 to 2 sentences.

Question 6

What is the destination and delay time (in hrs) for the flight that was most delayed?

Write a dplyr pipeline to answer this question. Then, explain the result of your pipeline in one sentence.

Question 7

Find the tail number of JetBlue flight 40 that traveled from SFO to to New York’s JFK Airport on May 1st. Use a single pipeline to find this flight.

Question 8

Part A

What proportion of all flights left on schedule? Write a dplyr pipeline to answer this question.

Part B

What proportion flights left on schedule for each airport (OAK and SFO)? Write a dplyr pipeline to answer this question.

Question 9

The plot below shows a relationship between the number of flights going out of SFO and the average departure delay. It would support the hypothesis that more flights on a given day would lead to a more congested airport which would lead to greater delays on average. Each point represents a single day in 2020; there are 366 of them on the plot.

Part A

Describe the variables featured in the plot and their aesthetic mappings according to the Grammar of Graphics.

Part B

Describe the settings that you see, if any, according to the Grammar of Graphics.

Part C

Form a single dplyr pipeline that will reproduce the plot, starting with the original flights data frame. This link might be helpful!

Last Question

Will you ensure that your submission to Gradescope…

  1. is a pdf generated from a qmd file
  2. your code is fully visible (not running off the page)
  3. follows formatting rules (here)
  4. and assigns each of the questions to all pages that show your work for that question?

(This one is easy! Just answer “yes” or “no”)