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.4.4 ✔ 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
library(nycflights13)
head(flights)
## # A tibble: 6 × 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 2013 1 1 517 515 2 830 819
## 2 2013 1 1 533 529 4 850 830
## 3 2013 1 1 542 540 2 923 850
## 4 2013 1 1 544 545 -1 1004 1022
## 5 2013 1 1 554 600 -6 812 837
## 6 2013 1 1 554 558 -4 740 728
## # ℹ 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>
flights |>
filter(!is.na(dep_delay), !is.na(arr_delay)) |>
ggplot(aes(x = dep_delay, y = arr_delay, color = carrier)) +
geom_point() +
labs(
title = "NYC Flights: Departure Delay vs Arrival Delay",
x = "Departure Delay (minutes)",
y = "Arrival Delay (minutes)",
caption = "Source: nycflights13"
) +
theme_minimal() +
theme(legend.position = "bottom")
For this weeks assignment I created a ggplot to show flights that both departed and arrived after their schedule time. To do so I filtered out any missing information from the “Departure” and “Arrival” columns in NYCFlights13. Then, I used the labs function to label and add captions where it was necessary. The aspect of this visualization that I would like to highlight is how long some of the delays are. Most flights fall under 500 minutes, but theres a few that were 1000+ minutes behind schedule. Thats 16 hours worth of delay.