library(tidyr)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)library(tidyr)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)takeout_spending <- data.frame(
Generation = c("Gen Z", "Millennials", "Gen X", "Baby Boomers", "Silent Gen"),
`Jan.2025` = c(185, 240, 195, 120, 75),
`Feb.2025` = c(172, 228, 188, 115, 70),
`Mar.2025` = c(198, 255, 205, 130, 82),
`Apr.2025` = c(210, 270, 215, 140, 88),
`May.2025` = c(205, 265, 210, 135, 85),
`Jun.2025` = c(225, 285, 220, 145, 90),
check.names = FALSE
)
# ── Save as CSV ──────────────────────────────────────────────────
write.csv(takeout_spending, "takeout_spending.csv", row.names = FALSE)url <- "https://raw.githubusercontent.com/AslamF/DATA607-Project-2/refs/heads/main/takeout_spending.csv"
raw_data <- read.csv(url)
glimpse(raw_data)Rows: 5
Columns: 7
$ Generation <chr> "Gen Z", "Millennials", "Gen X", "Baby Boomers", "Silent Ge…
$ Jan.2025 <int> 185, 240, 195, 120, 75
$ Feb.2025 <int> 172, 228, 188, 115, 70
$ Mar.2025 <int> 198, 255, 205, 130, 82
$ Apr.2025 <int> 210, 270, 215, 140, 88
$ May.2025 <int> 205, 265, 210, 135, 85
$ Jun.2025 <int> 225, 285, 220, 145, 90
tidy_spending <- raw_data |>
pivot_longer(
cols = -Generation, # pivot everything EXCEPT Generation
names_to = "month", # column names become values in "month"
values_to = "spending" # numbers go into "spending"
)
## Rename and standarize naming
tidy_spending <- tidy_spending |>
rename_with(tolower) |> # lowercase all column names
mutate(
month = gsub("\\.", "-", month), # fix "Jan.2025" → "Jan-2025"
month = as.Date(paste0("01-", month), # convert to proper Date
format = "%d-%b-%Y")
)
tidy_spending |>
print(n = 20)# A tibble: 30 × 3
generation month spending
<chr> <date> <int>
1 Gen Z 2025-01-01 185
2 Gen Z 2025-02-01 172
3 Gen Z 2025-03-01 198
4 Gen Z 2025-04-01 210
5 Gen Z 2025-05-01 205
6 Gen Z 2025-06-01 225
7 Millennials 2025-01-01 240
8 Millennials 2025-02-01 228
9 Millennials 2025-03-01 255
10 Millennials 2025-04-01 270
11 Millennials 2025-05-01 265
12 Millennials 2025-06-01 285
13 Gen X 2025-01-01 195
14 Gen X 2025-02-01 188
15 Gen X 2025-03-01 205
16 Gen X 2025-04-01 215
17 Gen X 2025-05-01 210
18 Gen X 2025-06-01 220
19 Baby Boomers 2025-01-01 120
20 Baby Boomers 2025-02-01 115
# ℹ 10 more rows
ggplot(tidy_spending, aes(x = month, y = spending, color = generation, group = generation)) +
geom_line(linewidth = 0.8) +
geom_point(size = 1) +
labs(
title = "Monthly Takeout Spending Trends by Generation (2025)",
x = "Month",
y = "Average Spending ($)",
color = "Generation"
) +
theme_minimal()Millennials consistently led takeout spending in early 2025 with a peak of $285.00. Every generation had an upward trend although some is less noticable such as silent g and baby boomers. Younger generations spend more on takeout than older generations however all groups have an increasing trend to spend on takeout.