library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
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.4 ✔ 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(ggplot2)
library(lubridate)
transactions <- transactions_sample
demographics %>%
filter(kids_count >= 2) %>%
inner_join(transactions, by = "household_id") %>%
group_by(kids_count) %>%
summarize(total_sales = sum(sales_value)) %>%
ggplot(aes(x = kids_count, y = total_sales))+
geom_col()+
labs(title = "Sales Value for household with 2 or more kids")

products %>%
filter(department == c("GROCERY", "DRUG GM", "MISCELLANEOUS", "PASTRY")) %>%
inner_join(transactions, by = "product_id") %>%
group_by(department) %>%
summarise(total_sales = sum(sales_value)) %>%
ggplot(aes(x = total_sales, fct_reorder(department,total_sales)))+
geom_col()+
scale_y_discrete(name = "Departments")+
labs(title = "Total Sales by Department")
## Warning: There was 1 warning in `filter()`.
## ℹ In argument: `department == c("GROCERY", "DRUG GM", "MISCELLANEOUS",
## "PASTRY")`.
## Caused by warning in `department == c("GROCERY", "DRUG GM", "MISCELLANEOUS", "PASTRY")`:
## ! longer object length is not a multiple of shorter object length

transactions %>%
inner_join(products, by = "product_id") %>%
inner_join(demographics, by = "household_id") %>%
group_by(brand,marital_status) %>%
mutate(marital_status = fct_recode(marital_status, Unknown = "NA")) %>%
summarize(total_quantity = sum(quantity)) %>%
ggplot(aes(x = marital_status, y = total_quantity))+
geom_point()+
facet_wrap(~ brand)+
scale_y_log10(labels = scales::label_comma())+
labs(title = "Total Quantity vs. Marital Status by Brand")
## Warning: There were 6 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `marital_status = fct_recode(marital_status, Unknown = "NA")`.
## ℹ In group 1: `brand = National` and `marital_status = Married`.
## Caused by warning:
## ! Unknown levels in `f`: NA
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 5 remaining warnings.
## `summarise()` has grouped output by 'brand'. You can override using the
## `.groups` argument.
