Assignment 7

Author

Brian Dibra

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Go to the shared posit.cloud workspace for this class and open the assign07 project. 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.

library(skimr)
library(gt)
flights <- read.csv("https://jsuleiman.com/datasets/domestic_flights_jan_2016.csv")

Question 1: Which airport had the most flight cancellations in January 2016?

cancellations_by_airport <- flights %>%
  group_by(Origin) %>% 
  summarise(cancelled_flights = sum(Cancelled, na.rm = TRUE)) %>%
  arrange(desc(cancelled_flights))
print(cancellations_by_airport)
# A tibble: 294 × 2
   Origin cancelled_flights
   <chr>              <int>
 1 EWR                  824
 2 BWI                  631
 3 DCA                  609
 4 CLT                  589
 5 LGA                  542
 6 JFK                  482
 7 SFO                  419
 8 ATL                  414
 9 ORD                  359
10 PHL                  345
# ℹ 284 more rows
top_10_airports <- cancellations_by_airport %>% 
  head(10)
print(top_10_airports)
# A tibble: 10 × 2
   Origin cancelled_flights
   <chr>              <int>
 1 EWR                  824
 2 BWI                  631
 3 DCA                  609
 4 CLT                  589
 5 LGA                  542
 6 JFK                  482
 7 SFO                  419
 8 ATL                  414
 9 ORD                  359
10 PHL                  345
ggplot(top_10_airports, aes(x = reorder(Origin, cancelled_flights), y = cancelled_flights, fill = Origin)) +
  geom_bar(stat = "identity") +
  labs(title = "Top 10 Airports by Flight Cancellations (January 2016)",
       x = "Airport",
       y = "Number of Cancellations") +
  theme_minimal() +
  coord_flip()

Question 1 Answer: It seems that Newark Liberty International Airport (EWR) has the most cancellations with 824.

Question 2: Which flight carrier had the most cancellations?

library(lubridate)
cancellations_by_carrier <- flights %>%
  group_by(Carrier) %>% 
  summarise(Cancelled = sum(Cancelled, na.rm = TRUE)) %>% 
  arrange(desc(Cancelled))
print(cancellations_by_carrier)
# A tibble: 12 × 2
   Carrier Cancelled
   <chr>       <int>
 1 AA           2720
 2 WN           2640
 3 EV           1427
 4 UA           1336
 5 OO            984
 6 DL            974
 7 B6            897
 8 NK            308
 9 VX            159
10 AS            139
11 F9             77
12 HA              4
ggplot(cancellations_by_carrier, aes(x = reorder(Carrier, -Cancelled), y = Cancelled, fill = Carrier)) +
  geom_bar(stat = "identity") +
  labs(title = "Flight Cancellations by Carrier (January 2016)",
       x = "Carrier",
       y = "Number of Cancelled Flights") +
  theme_minimal() +
  coord_flip()

Question 2 Answer: According to the data, American Airlines (AA) has the most cancellations, with 2720.

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.