# Load Libraries
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
#Create Data Frame
df <- transactions_sample %>%
  inner_join(demographics, by = "household_id")
df %>%
  group_by(age) %>%
  summarize(total_coupon_disc = sum(coupon_disc)) %>%
  ggplot(aes(age , total_coupon_disc)) +
  geom_col(color = "blue") +
  scale_y_continuous(labels = scales::dollar_format() ) +
  labs(title = "Customers Who Redeem Coupons",
    subtitle = "Household transaction data covering 2017.",
    x = "Age Group of Customer",
    y = "Total Amount of Coupons Redeemed")

df %>%
  filter(age == "45-54", coupon_disc > 0) %>%
  group_by(income) %>%
  summarise(total_coupon = sum(coupon_disc)) %>%
  ggplot(aes(total_coupon, income)) +
  geom_col(color = "green") +
  scale_x_continuous(labels = scales::dollar_format()) +
  labs(title = "Income of Customers 45-54 Who Redeem Coupons",
  subtitle = "Household transaction data covering 2017.",
  x = "Total Amount of Coupons Reemed",
  y = "Income Bracket of Consumer")

df %>%
  filter(age == "45-54", income == "50-74K", coupon_disc > 0) %>%
  ggplot(aes(coupon_disc, sales_value, color = home_ownership)) +
  geom_point(na.rm = TRUE) +
  scale_x_log10(labels = scales::dollar_format()) +
  scale_y_continuous(labels = scales::comma_format()) +
  scale_color_brewer(palette = "Set1") +
  labs(title = "Transaction Amount per Coupon Redeemed",
  subtitle = "For Age group 45-54 and Income level 50-74K",
  x = "Coupon Amount Redeemed",
  y = "Toal Sale",
  color = "Home Ownership")