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.
transactions <- transactions_sample
products <- products
transactions %>%
  inner_join(products) %>%
  ggplot(aes(x = week, y = sales_value, color = brand)) +
  geom_point(alpha = 0.2) +
  scale_y_continuous(name = 'Sales Value') +
  scale_x_continuous(name = 'Week of The Year') +
  labs(title = 'Brand Sales Throughout The Year')
## Joining with `by = join_by(product_id)`

transactions %>%
  inner_join(demographics) %>%
  group_by(income) %>%
  summarise(total_sales = sum(sales_value, na.rm = TRUE)) %>%
  ggplot(aes(x = total_sales, y = income)) +
  geom_point(color = 'darkgreen', size = 5, shape = 15) +
  xlab("Total Sales") +
  ylab("Income Ranges") +
  ggtitle("Total Spend For Each Income Range")
## Joining with `by = join_by(household_id)`

products %>%
  left_join(transactions) %>%
  filter(str_detect(product_category, regex('coffee', ignore_case = TRUE))) %>%
  group_by(product_category) %>%
  summarise(avg_sales = mean(sales_value, na.rm = TRUE)) %>%
  arrange(avg_sales) %>%
  ggplot(aes(x = avg_sales, y = product_category)) + 
  geom_point(size = 4, color = "orange") +
  xlab('Average Sales') +
  ylab('Types of Coffee Sold') +
  ggtitle('Average Sales For Each Type of Coffee')
## Joining with `by = join_by(product_id)`