Pre-Requisite to Rendering the Graphs: Load Needed Packages

library(ggplot2)
library(dplyr) 
library(completejourney)
library(tidyverse)
library(lubridate)

Graph 1

transactions_sample %>%
  inner_join(products) %>%
  inner_join(demographics) %>%
  filter(product_category == "SUSHI") %>%
  group_by(income) %>%
  summarize(total_sushi_purchases = sum(quantity, na.rm = TRUE)) %>%
  ggplot(aes(x=income, y=total_sushi_purchases, fill=total_sushi_purchases)) + 
  geom_col() + 
  labs(
    title = "Sushi Purchase Counts by Annual Income",
    subtitle = "Hypothesis: Higher Income Level customers (150k+) will \n have the most sushi purchases because sushi is expensive.",
    x = "Annual Income Levels ($)",
    y = "Count of Sushi Purchases") +  
  theme(plot.title = element_text(hjust = 0.5, face = "bold")) +
  theme(plot.subtitle = element_text(hjust = 0.5, face = "italic")) +
  annotate("text", x = 4, y= 5, label = "Wow! Shocked!")

Graph 2

demographics %>%
  inner_join(coupon_redemptions) %>%
  group_by(month(redemption_date), income) %>%
  summarize(redemption_count = n()) %>%
  ggplot(aes(x=`month(redemption_date)`,y=redemption_count)) + 
  geom_line() + 
  facet_wrap(~ income) + 
  scale_x_continuous(breaks = seq(1, 12, by = 1)) + 
  theme(axis.text.x = element_text(angle = 90)) + 
  labs(
    title = "Monthly Coupon Redemption Counts by Income Category",
    subtitle = "Hypothesis: Middle Class Income (50K - 99K) will \n have the most coupon redemptions most months",
    x = "Month (1 = January, 2 = February, ...)",
    y = "Coupon Redemption Count") + 
  theme(plot.title = element_text(hjust = 0.5, face = "bold")) + 
  theme(plot.subtitle = element_text(hjust = 0.5, face = "italic"))

Graph 3

transactions_sample %>%
  inner_join(products) %>%
  filter(department == "GROCERY") %>%
  mutate(day_of_week = wday(transaction_timestamp, label = TRUE)) %>%
  mutate(transaction_date = substring(transaction_timestamp, 1, 10)) %>%
  group_by(day_of_week, transaction_date) %>%
  summarize(total_purchases = sum(quantity)) %>%
  ggplot(aes(x= factor(day_of_week), y= total_purchases)) + 
  geom_boxplot(fill = "blue") + 
  labs(
    title = "Grocery Department Items -- Boxplot by Weekday",
    subtitle = "Hunch: There will be more variation and volume of purchases on weekends because people \n are more available/flexible on weekends",
    x = "Day of the Week",
    y = "Daily Purchase Count") + 
  theme(plot.title = element_text(hjust = 0.5, face = "bold")) + 
  theme(plot.subtitle = element_text(hjust = 0.5, face = "italic"))