flights_carrier_replaced <- flights_nona %>%mutate(carrier =recode(carrier,"DL"="Delta","AA"="American","B6"="JetBlue","AS"="Alaska","UA"="United","NK"="Spirit","WN"="Southwest","YX"="Republic","9E"="Endeavor","MQ"="Envoy","G4"="Allegiant","OO"="Skywest","F9"="Frontier","HA"="Hawaii"))# found this code here >>> https://www.geeksforgeeks.org/how-to-replace-multiple-values-in-data-frame-using-dplyr/flights_origin_replaced <- flights_carrier_replaced %>%mutate(origin =recode(origin, "EWR"="Newark","JFK"="John F. Kennedy","SMF"="Sacramento","ATL"="Hartsfield-Jackson Atlanta","BQN"="Aeropuerto","CHS"="Charleston","DTW"="Detroit Metropolitan Wayne County","MIA"="Miami","ORD"="Chicago O'Hare","IAH"="George Bush Intercontinental","FLL"="Fort Lauderdale-Hollywood","LGA"="LaGuardia","DEN"="Denver","MSP"="Minneapolis–Saint Paul"))flights_airport_replaced <- flights_origin_replaced %>%mutate(dest =recode(dest,"EWR"="Newark","JFK"="John F. Kennedy","SMF"="Sacramento","ATL"="Hartsfield-Jackson Atlanta","BQN"="Aeropuerto","CHS"="Charleston","DTW"="Detroit Metropolitan Wayne County","MIA"="Miami","ORD"="Chicago O'Hare","IAH"="George Bush Intercontinental","FLL"="Fort Lauderdale-Hollywood","LGA"="LaGuardia","DEN"="Denver","MSP"="Minneapolis–Saint Paul","PBI"="Palm Beach","BNA"="Nashville","MCO"="Orlando","MYR"="Myrtle","MDW"="Chicago Midway","SEA"="Seattle–Tacoma","CLE"="Cleveland Hopkins","SJU"="Luis Munoz Marin","PHX"="Phoenix Sky Harbor","STT"="Cyril E. King","TPA"="Tampa","PIT"="Pittsburgh","CMH"="John Glenn Columbus","DAL"="Dallas Love Field","RSW"="Southwest Florida","SLC"="Salt Lake City","STL"="St. Louis Lambert","BZN"="Bozeman Yellowstone","SFO"="San Francisco","DFW"="Dallas Fort Worth","DCA"="Ronald Reagan Washington","SNA"="John Wayne", "BOS"="Boston Logan","SAN"="San Diego","SAV"="Savannah/Hilton Head","SDF"="Louisville","CLT"="Charlotte Douglas","PWM"="Portland","RDU"="Raleigh-Durham","SRQ"="Sarasota Bradenton","SYR"="Syracuse Hancock","MSY"="Louis Armstrong New Orleans","AUS"="Austin-Bergstrom","BUR"="Hollywood Burbank","JAX"="Jacksonville","LAS"="Harry Reid","EGE"="Eagle County Regional","PHL"="Philadelphia","CVG"="Cincinnati/Northern Kentucky","AVL"="Asheville Regional","PSP"="Palm Springs", "PDX"="Portland" ))# Did not get to all airports
library(treemap)treemap(delay_flights_order, index="carrier", vSize="dist", vColor="delay", type="manual", border.col =c("white"), border.lwds =c(7), title ="Distance Travelled in Relation to Delay Time", title.legend ="Delay", palette="Reds")
## Caption- Pre-built dataset, nycflights23 is a package that contain information about all flights that departed from the three main New York City airports in 2023 and metadata on airlines, airports, weather, and planes.
Write a brief paragraph that describes the visualization you have created and at least one aspect of the plot that you would like to highlight.
The visualization that I have created is a tree map of the relationship between the average distance traveled and the average arrival delay of the top 20 airlines, arranged from earliest to latest arrival. The variables are visualized through 2 components of the tree map: size and color. The average distance is visualized through the size of each box. The bigger the box, the greater the average distance traveled by an airline. Whereas, the average arrival delay is depicted through a color gradient. The colors pertaining to a darker shade indicate that the average arrival delay is later, compared to a lighter color which indicates the average to be an early arrival made by an airline. The highlight of the plot that I found interesting was how, the smaller the average distance (for example Allegiant and Republic), the chances of the airline arriving early seems to be more likely. In comparison, the airline Hawaii is bigger and in red, indicating that although Hawaii airlines had a higher average travel distance, its average arrival delay tends to be late. However, the hypothesis of “the smaller the rectangle, the earlier the airline would arrive,” is immediately shut down because the airline Frontier is also smaller in size, but in dark red, which contradicts this statement, requiring further investigation.