NYC Flights

Author

Oluwatosin Akinmoladun

Load library tidyverse

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.2     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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

Load the Flights and Airlines Datasets

library(nycflights23)
data(flights)
data(airlines) 

Summarize the number of flights per airline

flights_summary <- flights |>
  group_by(carrier) |>
  summarize(total_flights = n()) |>
  left_join(airlines, by = "carrier") 

Create the bar plot

flights_summary |>
  ggplot(aes(x = name, y = total_flights, fill = name)) +
  geom_col() +
  labs(
    title = "Total Number of Flights by Airline",
    x = "Airline",
    y = "Number of Flights",
    fill = "Airline",
    caption ="Source: Flight data from nycflights23 package") +
  theme_minimal() + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) # source from chatgpt to properly let me label my x axis