library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
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)

Plot 1

income_breakdown <- transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  filter(week == 25) %>%                            
  group_by(income) %>%
  summarize(total_sales = sum(sales_value, na.rm = TRUE), .groups = "drop")
ggplot(income_breakdown, aes(x = reorder(income, total_sales), y = total_sales)) +
  geom_col(fill = "steelblue") +
  coord_flip() +
  labs(
    title = "Income Breakdown for Customers (Week 25)",
    x = "Income Bracket",
    y = "Total Sales ($)"
  )

Plot 2

data <- transactions_sample %>%
  inner_join(products, by = "product_id")

top5_products <- data %>%
  filter(week == 25) %>%
  group_by(product_id, product_type) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE), .groups = "drop") %>%
  arrange(desc(total_sales)) %>%
  slice_head(n = 5)
ggplot(top5_products, aes(x = reorder(product_type, total_sales), 
                          y = total_sales, fill = product_type)) +
  geom_col(show.legend = FALSE) +
  coord_flip() +
  labs(title = "Top 5 Products by Sales Value (Week 25)",
       x = "Product Type",
       y = "Total Sales Value") +
  theme_minimal()

Plot 3

age_breakdown <- transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  filter(week == 1) %>%
  group_by(age) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE), .groups = "drop") %>%
  arrange(desc(total_sales))
ggplot(age_breakdown, aes(x = reorder(age, total_sales), 
                          y = total_sales, fill = age)) +
  geom_col(show.legend = FALSE) +
  coord_flip() +
  labs(title = "Sales Breakdown by Age Group (Week 1)",
       x = "Age Group",
       y = "Total Sales Value") +
  theme_minimal()