Assignment 7

Author

Annalise Spaulding

Open the assign07.qmd file and complete the exercises.

This is somewhat open-ended assignment.

The file domestic_flights_jan_2016.csv is nearly the same as the me_flights.csv file we work with in the temporal data chapter except it has two additional columns for destination city and state and it is for all domestic flights reported for on-time performance in the US for January 2016. You’ll find it helpful to recreate all of the calculated fields we create in the unit.
You are to write a report uploaded to RPubs that compares what you consider interesting metrics for a select group of carriers, airports, or states. You may not parrot the queries from the text or the practice questions. Your report must contain at least two questions that you ask about the flights data. Your answers to those questions must also contain a visualization of the data or a table along with a specific answer in the narrative.


The csv file contains 445,827 observations. You’ll want to subset the data to the area(s) you are looking at, then write it out to a csv file using write_csv(), and start your assignment by importing that csv instead. Do this in a separate script file that you don’t need to submit. In your narrative, describe your subset. I don’t need to see how you subsetted the data because it might cause performance issues when you render the document. Note: you will receive deductions for not using tidyverse syntax in this assignment. That includes the use of filter, mutate, and the up-to-date pipe operator |>.

The Grading Rubric is available at the end of this document.

This is your work area. Add as many code cells as you need.

library(tidyverse)
library(gt)
library(scales)
flights <- read_csv("flights_subset.csv")
glimpse(flights)
Rows: 185,052
Columns: 21
$ FlightDate        <chr> "1/6/2016", "1/7/2016", "1/8/2016", "1/9/2016", "1/1…
$ Carrier           <chr> "AA", "AA", "AA", "AA", "AA", "AA", "AA", "AA", "AA"…
$ TailNum           <chr> "N4YBAA", "N434AA", "N541AA", "N489AA", "N439AA", "N…
$ FlightNum         <dbl> 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, …
$ Origin            <chr> "DFW", "DFW", "DFW", "DFW", "DFW", "DFW", "DFW", "DF…
$ OriginCityName    <chr> "Dallas/Fort Worth, TX", "Dallas/Fort Worth, TX", "D…
$ OriginState       <chr> "TX", "TX", "TX", "TX", "TX", "TX", "TX", "TX", "TX"…
$ Dest              <chr> "DTW", "DTW", "DTW", "DTW", "DTW", "DTW", "DTW", "DT…
$ DestCityName      <chr> "Detroit, MI", "Detroit, MI", "Detroit, MI", "Detroi…
$ DestState         <chr> "MI", "MI", "MI", "MI", "MI", "MI", "MI", "MI", "MI"…
$ CRSDepTime        <dbl> 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 1100…
$ DepTime           <dbl> 1057, 1056, 1055, 1102, 1240, 1107, 1059, 1055, 1058…
$ WheelsOff         <dbl> 1112, 1110, 1116, 1115, 1300, 1118, 1113, 1107, 1110…
$ WheelsOn          <dbl> 1424, 1416, 1431, 1424, 1617, 1426, 1429, 1419, 1420…
$ CRSArrTime        <dbl> 1438, 1438, 1438, 1438, 1438, 1438, 1438, 1438, 1438…
$ ArrTime           <dbl> 1432, 1426, 1445, 1433, 1631, 1435, 1438, 1431, 1428…
$ Cancelled         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ Diverted          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ CRSElapsedTime    <dbl> 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 15…
$ ActualElapsedTime <dbl> 155, 150, 170, 151, 171, 148, 159, 156, 150, 158, 14…
$ Distance          <dbl> 986, 986, 986, 986, 986, 986, 986, 986, 986, 986, 98…

For this assignment, i selected a subset of full flights data set of Delta, United, and American.

delay_summary <- flights |> 
  group_by(Carrier) |> 
  summarize(avg_arr_delay = mean(ArrTime - CRSArrTime, na.rm = TRUE)) |> 
  arrange(desc(avg_arr_delay))

delay_summary |> 
  gt() |> 
  fmt_number(columns = avg_arr_delay, decimals = 1) |> 
  tab_header(
    title = "Average Arrival Delay by Carrier (Jan 2016)",
    subtitle = "DL = Delta, UA = United, AA = American Airlines"
  )
Average Arrival Delay by Carrier (Jan 2016)
DL = Delta, UA = United, AA = American Airlines
Carrier avg_arr_delay
AA −10.0
DL −15.7
UA −18.0

United and Delta had a stronger early arrival performance compared to American

flight_counts <- flights |> 
  count(Carrier) |> 
  arrange(desc(n))

flight_counts |> 
  ggplot(aes(x = Carrier, y = n, fill = Carrier)) +
  geom_col() +
  labs(
    title = "Number of Flights per Carrier (Jan 2016)",
    x = "Carrier",
    y = "Number of Flights"
  ) +
  scale_y_continuous(labels = comma) +
  theme_minimal()

American had the highest number of flights recorded, then Delta, then United.

1 Submission

To submit your assignment:

  • Change the author name to your name in the YAML portion at the top of this document
  • Render your document to html and publish it to RPubs.
  • Submit the link to your Rpubs document in the Brightspace comments section for this assignment.
  • Click on the “Add a File” button and upload your .qmd file for this assignment to Brightspace.

2 Grading Rubric

Item
(percent overall)
100% - flawless 67% - minor issues 33% - moderate issues 0% - major issues or not attempted
Question 1 query.
(22%)
Relevant question that is fully answered in the query or queries.
Question 1 visualization or table.
(15%)
Visually pleasant and relevant to the question.
Question 2 query.
(22%)
Relevant question that is fully answered in the query or queries.
Question 2 visualization or table.
(15%)
Visually pleasant and relevant to the question.
Data was subsetted separately from the assignment.
(10%)
You included the description of your subsetted data in your narrative. You subsetted the data but didn’t include the description in the narrative. NA You didn’t subset the data.
Messages and/or errors suppressed from rendered document and all code is shown.
(8%)
Submitted properly to Brightspace
(8%)
NA NA You must submit according to instructions to receive any credit for this portion.