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.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ 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(dplyr)
library(lubridate)
library(ggplot2)
library(forcats)
Plot 1: Total Pizza Sales By Month
transactions <- get_transactions()
pizza_pick <- products %>%
filter(str_detect(product_type, regex('pizza', ignore_case = TRUE))) %>%
inner_join(transactions, by = "product_id") %>%
group_by(Month = month(transaction_timestamp, label = TRUE, abbr = TRUE)) %>%
mutate(month = month(transaction_timestamp)) %>%
summarise(total_sales = sum(sales_value))
pizza_pick %>%
ggplot(aes(Month, total_sales)) +
coord_cartesian(ylim = c(0, 7500)) +
geom_col(fill = "orange", color = "darkorange") +
labs(title = "Total Pizza Sales by Month",
x = "Month",
y = "Total Sales ($)")

Plot 2: Top Product Categories by age group
EH <- transactions %>%
inner_join(products, by = 'product_id') %>%
inner_join(demographics, by = 'household_id') %>%
group_by(product_category, age) %>%
summarise(sales = sum(sales_value)) %>%
arrange(desc(sales)) %>%
head(75)
## `summarise()` has grouped output by 'product_category'. You can override using
## the `.groups` argument.
EH %>%
ggplot(aes(x = reorder(product_category, sales, FUN = sum),
y = sales,
fill = age
)
) +
geom_col() +
coord_flip() +
labs(
title = 'Top Product Categories By Age Group',
y = 'Total Net Sales ($)',
x = 'Product Category',
subtitle =
'Shows Most popular product
categories sold in 2017.'
) +
guides(fill = guide_legend(title = "Age")) +
theme(plot.title = element_text(face = "bold", size = 15),
plot.subtitle = element_text(size = 9),
axis.text = element_text(size = 7)
)

Plot 3: Total Sales by month of frozen products for national and
private brands
product_point <- products %>%
filter(str_detect(product_type, regex('FRZN|FROZEN', ignore_case = TRUE))) %>%
inner_join(transactions_sample, by = 'product_id') %>%
group_by(month = month(transaction_timestamp, label = TRUE), brand) %>%
summarize(total_qty = sum(quantity)) %>%
ggplot(aes(total_qty, month)) +
geom_point() +
facet_wrap(~ brand) +
labs(x = "Total Sales of Frozen Products",
y = "Month",
subtitle = "Source: completejourney") +
ggtitle("Total Sales by Month of Frozen Products for National and Private Brand")
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
product_point +
geom_segment(aes(x = 0, xend = total_qty, y = month, yend = month),
size = .05)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
