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
library(nycflights23)
#Packages needed
#Open Up Data
data("flights")
# Cleaning The Data Via Week 3 Material
arrival_delays <- flights |>
##Filtering Origin specifically JFK
filter(origin %in% c("JFK")) %>%
##Grouped by character Carrier
group_by(carrier) %>%
#Instructed that the new variabled equals the result of the mean of arrival delay and making sure to ignore missing values
summarize(avg_arr_delay = mean(arr_delay, na.rm = TRUE)) %>%
#Arrange Data from descending order
arrange(desc(avg_arr_delay)) %>%
# keep rows from left join based on a common variable
left_join(airlines,by = "carrier")
#Resources I used in order to comprehend https://r4ds.hadley.nz/data-visualize.html Data Visualization, https://www.youtube.com/watch?v=n_ACYLWUmos&t=24s Bar Charts and Histograms using ggplot in R,
ggplot(arrival_delays, aes(x = reorder(name, -avg_arr_delay), y = avg_arr_delay, fill = name)) +
geom_bar(stat = "identity") +
# Resources used to create labels, https://rpubs.com/rsaidi/1141179 Plot 1 code
labs(
x = "Carrier",
y = "Average Arrival Delay (minutes)",
title = "Average Arrival Delays by Airline at JFK Airport",
caption = "Data source: nycflights23",
fill = "Airline Carrier"
#This part was what I struggled most to include https://www.youtube.com/watch?v=Er-tXfGkL08 Using ggplot to create bar chars, https://rpubs.com/rsaidi/1141179
) +
#https://www.statology.org/hjust-vjust-ggplot2/ Example 2 Move Axis Label Position in ggplot2
theme_light() +
theme(axis.text.x = element_text(angle = 50, hjust = 1))
The visualization represents the average arrival delays by various airlines at JFK Airport, displayed in a bar chart. Each airline is represented by a different color, making it easy to compare the delays across different carriers. The y-axis shows the average arrival delay in minutes, while the x-axis lists the airline carriers. This chart highlights that JetBlue Airways and SkyWest Airlines have the highest average delays, with JetBlue reaching over 20 minutes of average delay. In contrast, Alaska Airlines and Republic Airline stand out for having negative delay averages, meaning their flights generally arrive earlier than scheduled. One aspect I would like to highlight how some airlines, such as JetBlue, have much longer delays, while others, like Alaska Airlines, often arrive ahead of schedule. This shows there’s a big difference in performance between the airlines.