NYC Flights- Jason Laucel

#install.packages("nycflights13")
library(nycflights13)
library(RColorBrewer)
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.0
✔ 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
data(flights)
delayed_flights <- flights %>%
  filter(dep_delay > 0)
delay_summary <- delayed_flights %>%
  group_by(carrier) %>%
  summarise(num_delayed_flights = n()) %>%
  arrange(desc(num_delayed_flights)) 
# Arrange carriers by number of delayed flights
colors <- c("red", "blue", "green", "orange", "purple", "yellow", "cyan", "magenta", "brown", "grey","pink", "skyblue", "black", "tan", "navy", "violet")
ggplot(delay_summary, aes(x = carrier, y = num_delayed_flights, fill = carrier)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = colors) +  # Assign colors to carriers
  labs(title = "Number of Delayed Flights by Airline",
       x = "Airline",
       y = "# of Delayed Flights",
       caption = "Data Source: nycflights13") +
  theme_minimal() +
  theme(legend.position = "bottom") +
  guides(fill = guide_legend(title = "Airline"))

The visualization I created is a bar graph that shows delayed flights for all airlines. I decided to make the visualization straightforward and easy to follow. I wanted to highlight the placement of each piece of the visualization. There is a lot of information to cover for the legend and it’s the most I’ve had to organize thus far in any assignment. I was able to adjust the graph to be above the legend. Also, the legend itself was placed below the graph where it doesn’t clutter the entire visualization and is easy on the eye. Lastly, I also experimented with some new colors for the graph given the number of airlines.