library(tidyverse)
library(completejourney)
PLOT 1: Which income range redeemed most amount
of coupons?
coupon_redemptions %>%
inner_join(demographics, by = "household_id") %>%
group_by(income) %>%
tally() %>%
arrange(desc(n)) %>%
ggplot(aes(x = income, y = n, fill = n)) +
geom_col() +
scale_x_discrete("Income Range") +
scale_y_continuous("Total Coupons Redeemed") +
ggtitle("Who's redeeming coupons?",
subtitle = "Households with an income of 50-74K redeem the highest number of coupons")

PLOT 2: Which income range spends most on
different baby products?
products %>%
filter(str_detect(product_type, regex("BABY", ignore_case = TRUE))) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(income, product_type) %>%
summarize(total_sales = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(fill = product_type, x = income, y = total_sales)) +
geom_bar(position = "stack", stat = "identity") +
scale_x_discrete("Income Range") +
scale_y_continuous("Total baby product sales", labels = scales::dollar) +
ggtitle("What is the spending on different baby products?",
subtitle = "Households with an income of $50-74K buy the most baby products with the highest spending being Baby Diapers")

PART 3: Which frozen food categories provide
the highest retail discount?
products %>%
filter(str_detect(product_category, regex("FRZN|FROZEN", ignore_case = TRUE))) %>%
inner_join(transactions_sample, by = "product_id") %>%
group_by(product_category) %>%
summarise(total_retail_discount = sum(retail_disc, na.rm = TRUE)) %>%
ggplot( aes(x = product_category, y = total_retail_discount)) +
geom_bar(stat = "identity", fill = "purple", alpha = .6, width = .8) +
coord_flip() +
xlab("") +
theme_bw() +
scale_x_discrete("Frozen Product Category") +
scale_y_continuous("Total Retail Discount", labels = scales::dollar) +
ggtitle("Which product category for frozen food items provides the highest retail discount?",
subtitle = "The FRZN Meat/Meat Dinners Category provides the highest retail discount")
