library(tidyverse)
library(completejourney)

Plot 1: Who is saving the most money using coupons?

transactions_sample%>%
  inner_join(demographics, by = "household_id")%>%
  group_by(income, household_id)%>%
  summarise(coupons_avg = mean(coupon_disc), na.rm = TRUE)%>%
  ggplot(aes(x = income, y = coupons_avg)) +
  geom_col() +
  scale_x_discrete("Annual Income") + 
  scale_y_continuous("Average Savings From Coupons", labels = scales::dollar) + 
  ggtitle("Who is saving the most money using coupons?", 
          subtitle = "Households with an income of $50-74k save more on average than other income ranges.") + 
  theme_minimal()

Plot 2: What age group purchases the most makeup?

products %>%
  filter(str_detect(product_category, regex("(Makeup)", ignore_case = TRUE)))%>%
  inner_join(transactions_sample, by = "product_id")%>%
  inner_join(demographics, by = "household_id")%>%
  group_by(age)%>%
  summarise(totalsales = sum(quantity), na.rm = TRUE)%>%
  ggplot(aes(x = age, y = totalsales)) +
  geom_col() +
  scale_x_discrete("Age") + 
  scale_y_continuous("Number of Makeup Products Sold") + 
  ggtitle("What age group purchases the most makeup?", 
          subtitle = "People ages 35-44 purchase the most makeup.") + 
  theme_minimal()

Plot 3: Which store sells the most Christmas items?

products%>%
  filter(str_detect(product_category, regex("(CHRISTMAS)", 
                                            ignore_case = TRUE)))%>%
  inner_join(transactions_sample, by = "product_id")%>%
  group_by(store_id)%>%
  summarize(total_sales = sum(sales_value), na.rm = TRUE)%>%
  arrange(desc(total_sales)) %>%
  slice(1:10) %>%
  ggplot(aes(x = store_id, y = total_sales)) +
  geom_col() +
  scale_x_discrete("Store ID") + 
  scale_y_continuous("Total Sales of Christmas Items", labels = scales::dollar) +
  ggtitle("Which store sells the most Christmas items?", 
          subtitle = "Store 335 sold the most Christmas items.") + 
  theme_minimal()