Library Files to Load Data for Lab

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

Plot 1

library(tidyr)
library(tidyverse)
library(ggplot2)
library(completejourney)
library(dplyr)

cp_rd_1 <- coupon_redemptions
camp_1 <- campaigns
cp_dr_1 <- campaign_descriptions
demo_1 <- demographics
tran <- transactions_sample

monthlysales_data <- camp_1%>%
  inner_join(cp_dr_1, by =  "campaign_id")%>%
  inner_join(demo_1,by ="household_id") %>%
  inner_join(tran,by ="household_id") %>%
  mutate(month = month(transaction_timestamp))%>%
  mutate(sales = sum(sales_value))%>%
  ggplot(aes(x = age, y = sales, fill = age))+
  geom_col()+
  labs(title = "Monthly Sales by Age Group", x = "age", y = "Total Sales")
## Warning in inner_join(., tran, by = "household_id"): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 1 of `x` matches multiple rows in `y`.
## ℹ Row 1098 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
##   "many-to-many"` to silence this warning.
monthlysales_data

Plot 2

library(tidyr)
library(tidyverse)
library(ggplot2)
library(completejourney)
library(dplyr)

demo_1 <- demographics
transactions <- transactions_sample

Maratial_status <- demo_1%>%
  inner_join(transactions,by ="household_id") %>%
  mutate(sales = sum(sales_value))%>%
  group_by(age) %>%
  na.omit(marital_status)%>%
  ggplot() +
  geom_col(aes(x = household_size, y = marital_status, fill = marital_status))+
  scale_x_discrete("Household")+
  scale_y_discrete("Marriage Status")+
  ggtitle("Sales by Household Size and Marital Status")

Maratial_status

## Plot 3

library(tidyr)
library(tidyverse)
library(ggplot2)
library(completejourney)
library(dplyr)


tran_3 <- transactions
demo_3 <- demographics


products %>%
  filter(product_category == "COFFEE") %>%
  inner_join(tran_3) %>%
  inner_join(demo_3) %>%
  group_by(product_category) %>%
  mutate(time = hour(transaction_timestamp), keep = "all") %>%
  ggplot(aes(time)) +
  geom_bar(color = "pink")+
  labs(title = "Daily Coffee sales", x = "Time", y = "Sales") 
## Joining with `by = join_by(product_id)`
## Joining with `by = join_by(household_id)`