library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── 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
library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.

Plot 1

transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  group_by(week) %>%
  filter(kids_count > 2,
         week == c(45 : 52)) %>%
  summarise( total_sales = sum(sales_value)) %>%
  ggplot(aes(x = week, y = total_sales, color = week)) +
  geom_line(color = "turquoise4",
            lwd = 1.25) +
  labs(
    title = "Total Sales for Nov-Dec",
    subtitle = "Weeks 45-48 is Nov and 49-52 is Dec",
    x = "Week",
    y = "Total Sales"
  ) 

Plot 2

transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  group_by(household_id) %>%
  filter(quantity > 2,
         income < "75-99K") %>%
  ggplot(aes(x = income, y = sales_value, color = income)) +
  geom_jitter(alpha = 2) +
  facet_wrap(~ household_size) +
  labs(
    title = "Sales by Household Size", 
    subtitle = "With Income Under 75K",
    y = "Sales",
    x = "Income") +
  theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank()) +
  guides(color = guide_legend(title = "Income"))

Plot 3

transactions_sample %>%
  inner_join(products, by = "product_id") %>%
  group_by(basket_id) %>%
  filter(quantity > 9, 
         str_detect(department, c("NUTRITION|PASTRY|DRUG GM|MEAT-PCKGD|GROCERY")),
         sales_value > 5,
         quantity < 89) %>%
  mutate(avg_value = sales_value / quantity) %>% 
  ggplot(aes( x = quantity, y = avg_value, color = department)) + 
  geom_point(alpha = .65) +
  xlim(9, 35) +
  labs(
    title = "Avg Value Per Product for Packages with Over 10 Items adn $5",
    subtitle = "For Departments: Nutrition, Pastry, Drug GM, Packaged Meat",
    x = "Quantity",
    y = "Avg Value"
  ) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  guides(color = guide_legend(title = "Department"))