library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## Warning: package 'forcats' was built under R version 4.3.3
## Warning: package 'lubridate' was built under R version 4.3.3
## ── 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.4.4     ✔ 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)
## Warning: package 'completejourney' was built under R version 4.3.3
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
transactions<- transactions_sample
plot1<-transactions %>% 
  inner_join(products, by= "product_id") %>% 
  filter(department== "PASTRY") %>% 
  mutate(day_of_week= wday(transaction_timestamp)) %>% 
  group_by(product_category,day_of_week) %>% 
  summarize(total_sales= sum(sales_value))
## `summarise()` has grouped output by 'product_category'. You can override using
## the `.groups` argument.
ggplot(data=plot1, aes(x=total_sales)) +
  geom_boxplot() +
  facet_wrap(~day_of_week) +
  ggtitle("Pastry Sales by Day of Week", subtitle = "Sunday-Saturday") +
  xlab("Total Sales")

plot2<- transactions %>%
  inner_join(products, by= "product_id") %>%
  mutate(month= month(transaction_timestamp)) %>%
  group_by(brand, month) %>%
  summarise(total_sales=sum(sales_value))
## `summarise()` has grouped output by 'brand'. You can override using the
## `.groups` argument.
ggplot(data=plot2, aes(x=month, y=total_sales)) +
  geom_point() +
  facet_wrap(~brand) +
  ggtitle("National vs Private Brand Sales by Month", subtitle = "National Outpaces by Far") +
  ylab("Total Sales") +
  xlab("Month")

plot3 <- transactions %>%
  inner_join(demographics, by = "household_id") %>%
  inner_join(products, by = "product_id") %>%
  filter(department %in% c("DRUG GM", "GROCERY")) %>%
  group_by(income)
ggplot(data=plot3, aes(x=income)) +
  geom_bar() +
  ggtitle("Number of Purchases by Income and Department", subtitle = "Little proportional difference between Grocery and Drug GM") +
  facet_wrap(~department) +
  xlab("Income Level") +
  ylab("Number of Sales")