products %>%
  filter(str_detect(product_category, regex("(MAKEUP AND TREATMENT)", ignore_case = TRUE))) %>%
  inner_join(transactions_sample, by = "product_id") %>%
  inner_join(demographics, by = "household_id") %>%
  group_by(product_category, age) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE)) %>%
  mutate(age = fct_na_value_to_level(age, level = "Unknown")) %>%
  ggplot(aes(x = age, y = total_sales)) +
  geom_col(fill = "RED") +
  scale_x_discrete("Age") +
  scale_y_continuous("Total Makeup Sales", labels = scales::dollar) +
  ggtitle("Which age group is buying the most makeup?",
          subtitle = "People between the ages of 35 and 44 spend the most on makeup products.")

transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  filter(age == "35-44") %>%
  inner_join(products, by = "product_id") %>%
  group_by(product_id, product_type) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE)) %>%
  arrange(desc(total_sales)) %>%
  head(n = 5) %>%
  ggplot(aes(x = product_type, y = total_sales)) +
  geom_col(fill = "NAVY") +
  scale_y_continuous("Sales Volume", labels = scales::dollar) +
  scale_x_discrete("Product Type") +
  ggtitle("Top Products Purchased By 35-44 year old Adults",
          subtitle = "Gasoline is the most purchased product for this age range.")

products %>%
  filter(str_detect(product_category, "VITAMINS"), ignore_case = TRUE) %>%
  filter(str_detect(product_type, "VITAMIN"), ignore_case = TRUE) %>%
  inner_join(transactions_sample, by = "product_id") %>%
  inner_join(demographics, by = "household_id") %>%
  group_by(age, income) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE)) %>%
  ggplot(aes(x = age, y = total_sales)) +
  geom_col(fill = "PURPLE") +
  theme(axis.text.x = element_text(size = 6, angle = 45)) +
  facet_wrap(~ income) +
  scale_x_discrete("Age") +
  scale_y_continuous("Vitamin Sales Value", labels = scales::dollar) +
  ggtitle("What age range and income group buy the most vitamins?",
          subtitle = "People in the age range of 45-54 with an income range of 50-74k are buying the most vitamins.")