Packages
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
##
##
## Attaching package: 'scales'
##
##
## The following object is masked from 'package:purrr':
##
## discard
##
##
## The following object is masked from 'package:readr':
##
## col_factor
Plot 1
Do married or unmarried individuals consume more coffee?
products %>%
filter(product_category == "COFFEE") %>%
inner_join(transactions, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(income, 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)) +
theme_light() +
geom_col(fill = "lightblue", color = "black") +
facet_wrap(~ income) +
scale_x_discrete("Marital Status") +
scale_y_continuous("Total Coffee Sales",
labels = scales::dollar) +
ggtitle("Do Married or Unmarried Individuals Consume More Coffee?",
subtitle = "Coffee sales are higher amongst married couples, but overall consumption plummets after peaking at $50-74k")

Plot 2 Where do DIYers Reside?
products %>%
filter(str_detect(product_category, regex("(Hardware)|(Hard Surface)",
ignore_case = TRUE))) %>%
inner_join(transactions, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(home_ownership, age) %>%
summarize(total_sales = sum(sales_value, na.rm = TRUE)) %>%
mutate(home_ownership = fct_na_value_to_level(home_ownership, level = "Unknown")) %>%
ggplot(aes(x = age, y = total_sales)) +
geom_col(color = "black", fill = "orange") +
facet_wrap(~ home_ownership) +
scale_x_discrete("Residency Type") +
scale_y_continuous("Total Hard Product Sales",
labels = scales::dollar) +
ggtitle("DIY Households",
subtitle = "Hammers are very popular")

Plot 3 2017 Annual Heatmap
transactions$transaction_timestamp <- ymd_hms(transactions$transaction_timestamp)
transactions <- transactions %>%
mutate(date = as.Date(transaction_timestamp))
sales_by_date <- transactions %>%
group_by(date) %>%
summarize(total_sales = sum(sales_value))
ggplot(sales_by_date, aes(x = format(date, "%m"), y = format(date, "%d"),
fill = total_sales)) +
geom_tile() +
scale_fill_gradient(low = "yellow", high = "red", trans = "log",
labels = scales::dollar) +
labs(x = "Month", y = "Day",
title = "2017 Calendar Sales Heatmap",
subtitle = "There is Christmas, and then everyone else.") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
