Warning: package 'readr' was built under R version 4.4.3
Warning: package 'lubridate' was built under R version 4.4.2
── 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.1 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ 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
library(nycflights23)data(flights)data(airlines)
# Prepare the datamonthly_flights <- flights |>group_by(carrier, month) |>summarize(total_flights =n(), .groups ="drop") |>inner_join(airlines, by ="carrier")
# Create the streamgraphlibrary(ggstream)
Warning: package 'ggstream' was built under R version 4.4.3
streamgraph_viz <- monthly_flights |>ggplot(aes(x = month, y = total_flights, fill = name)) +geom_stream(type ="ridge", color ="black") +# Adds black outline for clarityscale_x_continuous(breaks =1:12, labels = month.abb) +# Label months with Jan, Feb, etc.scale_fill_manual(values =c("Alaska Airlines Inc."="#24fc03", # Blue"Allegiant Air"="#33a02c", # Green"American Airlines Inc."="#e31a1c", # Red"Delta Air Lines Inc."="#ff7f00", # Orange"Endeavor Air Inc."="#6a3d9a", # Purple"Envoy Air"="#b15928", # Brown"Frontier Airlines Inc."="#a6cee3", # Light blue"Hawaiian Airlines Inc."="#b2df8a", # Light green"JetBlue Airways"="#fb9a99", # Pink"Republic Airline"="#ED760E", # Light orange"SkyWest Airlines Inc."="#9e2498", # Lavender"Southwest Airlines Co."="#EDFF21", # Yellow"Spirit Air Lines"="#ff00ff", # Magenta (bright)"United Air Lines Inc."="#00ffff"# Cyan (bright) )) +labs(title ="Streamgraph of Monthly Flight Volumes by Airline",x ="Month",y ="Number of Flights",fill ="Airline",caption ="Data Source: nycflights23" ) +theme_minimal() +theme(plot.title =element_text(face ="bold", hjust =0.5),legend.position ="right" )streamgraph_viz
Note: I used ChatGPT assistance to label the x-axis with month abbreviations and to summarize and join flight data by month and carrier. ChatGPT also helped debug missing geom_stream library.