library(tidyverse)
library(completejourney)
#Plot 1
products %>%
filter(str_detect(product_category,"BEER"))%>%
inner_join(transactions_sample, by = "product_id")%>%
inner_join(demographics, by = "household_id")%>%
group_by(kids_count, age)%>%
summarise(total_sales = sum(sales_value, na.rm = TRUE))%>%
mutate(kids_count = fct_na_value_to_level(kids_count, level = "Unknown"))%>%
ggplot(aes(x = kids_count, y = total_sales)) +
geom_col() +
facet_wrap(~ age)+
scale_y_continuous("Total Sales for Beer", labels = scales :: dollar)+
scale_x_discrete("Kid Count") +
ggtitle("Who's Buying the Most Beer?",
subtitle = "Age Range 45-54 with No Kids Drink the Most Beer")
## `summarise()` has grouped output by 'kids_count'. You can override using the
## `.groups` argument.
#Plot 2
products %>%
filter(str_detect(product_category, "BEER")) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(age) %>%
filter(age == "45-54") %>%
filter(kids_count == "0") %>%
ggplot(aes(x = as.numeric(week), y = sales_value)) +
geom_col() +
scale_y_continuous("Total Sales for Beer", labels = scales::dollar_format()) +
scale_x_continuous(
"Week of the Year",
breaks = seq(1, 52, by = 4),
labels = c(0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48)
) +
ggtitle("When is the 45-54 age range with no kids buying beer?",
subtitle = "They drink the most around the Valentines Day")
#Plot 3
products %>%
filter(str_detect(product_category, "BEER")) %>%
inner_join(transactions_sample, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(quantity) %>%
ggplot(aes(x = quantity, y = sales_value)) +
geom_point(alpha = 0.314159) +
facet_wrap(~ kids_count) +
scale_y_continuous("Total Sales for Beer", labels = scales :: dollar) +
scale_x_continuous("Size of Order", breaks = c(0, 1, 2, 3, 4, 5),
labels = c("0", "1", "2", "3", "4", "5")) +
ggtitle("How much beer is purchased for each amount of kids in the house?",
subtitle = "The more kids you have, the less you buy")