title: "R Notebook" Author: "Tobin Smith" output: html_notebook --- ```{r} library(tidyverse) library(completejourney) library(ggplot2) library(lubridate)

ls("package:completejourney")

transactions <- gettransactions() promotions <- getpromotions() data("demographics") data("products") #### **Plot 1: Loyalty Programs Impact on Spending**{r} incomespending <- transactions %>% innerjoin(demographics, by = "householdid") %>% groupby(householdid, income) %>% summarize(totalspent = sum(sales_value, na.rm = TRUE), .groups = "drop")

incomespending %>% ggplot(aes(x = income, y = totalspent, fill = income)) + geomboxplot(show.legend = FALSE) + labs( title = "Does Household Income Impact Spending?", subtitle = "Comparing Total Spending per Household Across Income Levels", x = "Household Income Level", y = "Total Spending ($)", caption = "Data: completejourney" ) + thememinimal() #### **Plot 2: Discount Impact on Product Sales**{r message=TRUE, warning=TRUE} transactions %>% mutate(totaldiscount = coalesce(retaildisc, 0) + coalesce(coupondisc, 0 ) + coalesce(couponmatchdisc, 0)) %>% groupby(productid) %>% summarize(avgdiscount = mean(totaldiscount, na.rm = TRUE), totalsales = sum(salesvalue, na.rm = TRUE), .groups = "drop") %>% filter(totalsales < quantile(totalsales, .99)) %>% ggplot(aes(x = avgdiscount, y = totalsales)) + geompoint(alpha = .5, color = "blue") + geomsmooth(method = "lm", color = "red") + labs( title = "Do Discounts Boost Sales?", subtitle = "Comparing Total Sales with Average Discounts Applied", x = "Average Discount ($)", y = "Total Sales ($)", caption = "Data: completejourney" ) + thememinimal()

#### **Plot 3: Seasonal Spending Trends**{r} transactions %>% mutate(month = lubridate::month(transactiontimestamp, label = TRUE)) %>% groupby(month) %>% summarize(totalsales = sum(salesvalue, na.rm = TRUE), .groups = "drop") %>% ggplot(aes(x = month, y = totalsales, group = 1)) + geomline(color = "darkgreen", size = 1) + geompoint(color = "black", size = 3) + labs( title = "Seasonal Spending Trends", subtitle = "Tracking total sales per month", x = "Month", y = "Total Sales ($)", caption = "Data: CompleteJourney" ) + thememinimal() ```