library(tidyverse)
library(completejourney)
Which income range buys more cookies?
products %>%
filter(str_detect(product_category, ("COOKIES"))) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(income, age) %>%
summarize(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() +
facet_wrap(~ income) +
scale_y_continuous("Cookie Sales", labels = scales::dollar) +
scale_x_discrete("Age") +
ggtitle("Who buys the most cookies?",
subtitle = "The income ranges and ages of people based on how many cookies they buy.")

Does marital status effect how many baby products are bought?
products %>%
filter(str_detect(product_category, ("BABY"))) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(marital_status) %>%
summarize(total_sales = sum(sales_value, na.rm = TRUE)) %>%
mutate(marital_status = fct_na_value_to_level(marital_status, level = "unknown")) %>%
ggplot(aes(x = marital_status, y = total_sales)) +
geom_col() +
scale_y_continuous("Money Spent on Baby Products", labels = scales::dollar) +
scale_x_discrete("Marital Staus") +
ggtitle("Does marital status effect how many baby products are bought?",
subtitle = "More people who are married are more likely to by baby products compaired to those who are not married or have an unknown maratial status.")

Which household sizes buys the most coffee?
products %>%
filter(str_detect(product_category, ("COFFEE"))) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(household_size) %>%
summarize(total_sales = sum(sales_value, na.rm = TRUE)) %>%
mutate(household_size = fct_na_value_to_level(household_size, level = "unknown")) %>%
ggplot(aes(x = household_size, y = total_sales)) +
geom_col() +
scale_y_continuous("Coffee Sales", labels = scales::dollar) +
scale_x_discrete("Household Sizes") +
ggtitle("Does the size of the household effect the amount of coffee bought",
subtitle = "The smaller households seem to be buying more coffee than those that are bigger.")
