Week5_Assignment4

Author

Konci Lawrence

Week 5: Assignment 4

Name: Konci Lawrence

Due Date: 10/7/26

Load the libraries and view the “flights” dataset

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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
library(dplyr)
library(ggplot2)
library(nycflights23)
data(flights)

Look at the data

tibble(flights)
# A tibble: 435,352 × 19
    year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
   <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>
 1  2023     1     1        1           2038       203      328              3
 2  2023     1     1       18           2300        78      228            135
 3  2023     1     1       31           2344        47      500            426
 4  2023     1     1       33           2140       173      238           2352
 5  2023     1     1       36           2048       228      223           2252
 6  2023     1     1      503            500         3      808            815
 7  2023     1     1      520            510        10      948            949
 8  2023     1     1      524            530        -6      645            710
 9  2023     1     1      537            520        17      926            818
10  2023     1     1      547            545         2      845            852
# ℹ 435,342 more rows
# ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
#   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
#   hour <dbl>, minute <dbl>, time_hour <dttm>

Plot data

flights <- flights |> filter(carrier==c("AA","DL"),origin=="JFK") #represent only AA and DL with JFK as constant
ggplot(flights, aes(
  x=hour,
  y=distance,
  fill=carrier)) +
  geom_col() +
  labs(title = "American vs Delta Airlines", 
       caption = "Source: Tidyverse Flights Dataset") 

Observe change in data

flights
# A tibble: 21,872 × 19
    year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
   <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>
 1  2023     1     1       18           2300        78      228            135
 2  2023     1     1      655            700        -5     1044           1044
 3  2023     1     1      657            700        -3      902            927
 4  2023     1     1      709            700         9     1019           1028
 5  2023     1     1      726            730        -4     1054           1052
 6  2023     1     1      732            735        -3     1027           1045
 7  2023     1     1      736            735         1     1047           1101
 8  2023     1     1      754            759        -5     1105           1110
 9  2023     1     1      801            735        26     1111           1053
10  2023     1     1      819            829       -10     1111           1148
# ℹ 21,862 more rows
# ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
#   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
#   hour <dbl>, minute <dbl>, time_hour <dttm>

Summary

This box plot visualizes the Tidyverse Flights dataset. Specifically showing whether American Airlines (AA) or Delta Airlines (DL) has faster flights. The x-axis on this box plot represents the time of the flight in hours and the y-axis represents the distance of the flight. Specific to this visualization, American Airlines and Delta Airline are respectively represented by the colors red and blue as depicted in the legend. A highlight of this visualization is the use of the dplyr command, filter(), to hold the JFK airport as a constant for the origin of the flight and to only select data concerning American Airlines and Delta Airlines. JFK airport was chosen simply to narrow the data. From observing this dataset, one can conclude that American Airlines is capable of covering a greater distance than Delta Airlines in the same time frame. However, the downsides to this visualization are outliers due to influencing factors not depicted by a barplot.