Assignment4

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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)
data(flights)
monthly_flights <- flights %>%
  group_by(month) %>%
  summarize(number_of_flights = n()) %>%
  mutate(month = factor(month,
                        levels = 1:12,
                        labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")))
ggplot(monthly_flights, aes(x = month, y = number_of_flights, fill = month)) +
  geom_col() +
  labs(
    x = "Month",
    y = "Number of Flights",
    title = "Number of Flights by Month in 2023",
    caption = "Source: NYC Flights 2023 dataset (nycflights23)",
    fill = "Month"
  )

# This visualization is a bar graph showing the number of flights for each month in the NYC Flights dataset. The x-axis is the months of the year, while the y-axis is the total number of flights. Each month is displayed with a different color, and the legend shows the color that is with each month. I used the group_by and summarize functions to count the total number of flights for each month. One aspect that I would like to highlight is how the number of flights changes throughout the year. The bars make it easy to compare the number of flights between different months, and some months have noticeably more flights than others, which could be related to how travel changes between the seasons. Months during the summer could have higher flight numbers because more people travel during summer vacations. The graph provides a way to see these differences without needing to look through rows of the dataset. This visualization shows the monthly totals of flights and makes it easy to see which months had the most and least flights during 2023.