library(tidyverse)
library(completejourney)
transactions <- transactions_sample
Plot 1 - What number of kids in a married household buys the most
fruit?
transactions %>%
inner_join(products, by = "product_id") %>%
filter(str_detect(product_category, regex("FRUIT", ignore_case = TRUE))) %>%
inner_join(demographics, by = "household_id") %>%
filter(marital_status == "Married") %>%
group_by(kids_count) %>%
mutate(total_sales = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(x = kids_count, y = total_sales)) +
geom_col() +
scale_x_discrete("Number of Kids in Married Household") +
scale_y_continuous("Total Fruit Sales", label = scales::dollar) +
ggtitle("What number of kids in a married household buys the most fruit?",
subtitle = "Married households with no kids buy the most fruit")

Plot 2 - What month are married households with no kids buying the
most fruit?
transactions %>%
inner_join(products, by = "product_id") %>%
filter(str_detect(product_category, regex("FRUIT", ignore_case = TRUE))) %>%
inner_join(demographics, by = "household_id") %>%
filter(marital_status == "Married", kids_count == "0") %>%
mutate(month = month(transaction_timestamp, label = TRUE)) %>%
group_by(month) %>%
mutate(total_sales = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(x = month, y = total_sales)) +
geom_col() +
scale_x_discrete("Month") +
scale_y_continuous("Total Fruit Sales", label = scales::dollar) +
ggtitle("What month are married households with no kids buying the most fruit?",
subtitle = "Married households with no kids buy the most fruit in August")

Plot 3 - Who’s Buying Vitamins?
products %>%
filter(str_detect(product_category, regex("VITAMIN", ignore_case = TRUE))) %>%
inner_join(transactions, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(age, income) %>%
mutate(total_sales = sum(sales_value, na.rm = TRUE)) %>%
ggplot(aes(x = age, y = total_sales)) +
geom_col() +
facet_wrap(~income) +
scale_x_discrete("Age") +
scale_y_continuous("Total Vitamin Sales", label = scales::dollar) +
ggtitle("Who's Buying Vitamins?",
subtitle = "People who are 45-54 years old with income 50-74K are buying the most vitamins")
