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.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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(nycflights13)
data(flights)
flights_sum <- flights |>
group_by(month, carrier) |>
summarize(num_flights = n(), .groups = "drop") |>
left_join(airlines, by = "carrier")
head(flights_sum)
## # A tibble: 6 × 4
## month carrier num_flights name
## <int> <chr> <int> <chr>
## 1 1 9E 1573 Endeavor Air Inc.
## 2 1 AA 2794 American Airlines Inc.
## 3 1 AS 62 Alaska Airlines Inc.
## 4 1 B6 4427 JetBlue Airways
## 5 1 DL 3690 Delta Air Lines Inc.
## 6 1 EV 4171 ExpressJet Airlines Inc.
p1 <- flights_sum |>
ggplot(aes(x = month,
y = num_flights,
fill = name,
group = name)) +
geom_area(position = "stack", alpha = 0.9) +
labs(
x = "Month (1 = Jan, 12 = Dec)",
y = "Number of Flights",
title = "Monthly Airline Flight Activity in New York City (2013)",
caption = "Source: nycflights13 dataset",
fill = "Airline"
) +
theme_minimal()
p1
Essay Part
The graph I created is a streamgraph that shows the number of flights departing from New York City in 2013, separated by airline and month.Using dplyr, I grouped the data by month and airline to count how many flights each airline operated. Each color in the graph represents a different airline, and the width of each section shows how many flights that airline had in a given month. From the graph, we can see that the number of flights changes throughout the year, with the busiest months being around summer (June and July). Airlines like United, Delta, and JetBlue stand out because they consistently have the largest sections, meaning they operated the most flights. The visualization makes it easy to see which airlines were the most active and how flight activity changed over time during 2013.