library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.1 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── 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(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
# Load datasets
transactions <- transactions_sample
products <- products
demographics <- demographics
coupon_redemptions <- coupon_redemptions
campaigns <- campaigns
campaign_descriptions <- campaign_descriptions
Plot 1:- Higher income households spend more on premium products
transactions %>%
inner_join(products, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(income, product_category) %>%
summarise(total_sales = sum(sales_value), .groups = "drop") %>%
group_by(income) %>%
slice_max(total_sales, n = 5) %>%
ggplot(aes(x = reorder(product_category, total_sales),
y = total_sales,
fill = income)) +
geom_col() +
coord_flip() +
labs(
title = "Premium Product Spending is Dominated by Higher-Income Households",
subtitle = "Top 5 product categories by total sales within each income group",
x = "Product Category",
y = "Total Sales ($)",
fill = "Income Level",
caption = "Source: CompleteJourney Dataset"
) +
theme_minimal(base_size = 14)
Plot 2:- Coupon campaigns increase spending
transactions %>%
inner_join(coupon_redemptions, by = "household_id", relationship = "many-to-many") %>%
inner_join(campaigns, by = c("household_id", "campaign_id"), relationship = "many-to-many") %>%
inner_join(campaign_descriptions, by = "campaign_id") %>%
group_by(campaign_type) %>%
summarise(total_sales = sum(sales_value), .groups = "drop") %>%
ggplot(aes(x = campaign_type,
y = total_sales,
fill = campaign_type)) +
geom_col() +
labs(
title = "Campaign Type Strongly Influences Customer Spending Behavior",
subtitle = "Households exposed to different campaign types generate varying total sales",
x = "Campaign Type",
y = "Total Sales ($)",
fill = "Campaign Type",
caption = "Source: CompleteJourney Dataset"
) +
theme_minimal(base_size = 14)
Plot 3:-Family size influences spending
transactions %>%
inner_join(demographics, by = "household_id") %>%
group_by(household_size) %>%
summarise(total_sales = sum(sales_value), .groups = "drop") %>%
ggplot(aes(x = household_size,
y = total_sales,
fill = household_size)) +
geom_col() +
labs(
title = "Larger Households Spend Significantly More on Groceries",
subtitle = "Total grocery spending by household size",
x = "Household Size",
y = "Total Sales ($)",
fill = "Household Size",
caption = "Source: CompleteJourney Dataset"
) +
theme_minimal(base_size = 14)
```