library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
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.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
Distinct Plot 1
products %>%
filter(str_detect(product_category, regex("(CANDY)"))) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(age) %>%
summarize(total_sales = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(x = age, y = total_sales)) +
geom_col() +
scale_y_continuous("Total Sales for Candy", labels = scales::dollar) +
scale_x_discrete("Age") +
ggtitle("Which Age Group Has the Biggest Sweet Tooth?",
subtitle = "Age group '45-54' spends the most on candy")

Distinct Plot 2
products %>%
inner_join(transactions_sample, by = "product_id") %>%
filter(str_detect(department, regex("(PRODUCE)"))) %>%
group_by(product_category) %>%
summarize(coupon_sales =sum(coupon_disc, na.rm = TRUE)) %>%
ggplot(aes(x = coupon_sales, y = fct_reorder(product_category, coupon_sales)))+
geom_point(color = "red") +
labs(title = "Total Coupon Spend On Produce",
subtitle = "Salad Mix had the most coupons presented",
x = "Total Coupon Sales",
y = "Produce Item")

Distinct Plot 3
transactions_sample %>%
inner_join(demographics, by = "household_id") %>%
group_by(household_size, income) %>%
summarize(total_spend = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(x = household_size, y = total_spend)) +
scale_y_continuous("Total Spent", labels = scales::dollar) +
geom_col() +
scale_x_discrete("Household Size") +
facet_wrap(~income) +
ggtitle("Which household size spends the most?",
subtitle = "Consumers with households of 2, in the 50-74k range, spend the most ")
## `summarise()` has grouped output by 'household_size'. You can override using
## the `.groups` argument.
