library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
data("transactions_sample")
data("demographics")
trans_and_demog <- transactions_sample %>%
inner_join(demographics, by = "household_id")
quantity_by_household_size <- trans_and_demog %>%
group_by(household_size) %>%
summarise(total_quantity = sum(quantity, na.rm = TRUE)) %>%
filter(!is.na(household_size))
ggplot(quantity_by_household_size, aes(x = as.factor(household_size), y = total_quantity, fill = as.factor(household_size))) +
geom_bar(stat = "identity") +
labs(title = "Total Quantity Purchased by Household Size",
x = "Household Size",
y = "Total Quantity Purchased") +
theme_minimal()

quantity_by_week <- transactions_sample %>%
group_by(week) %>%
summarise(total_quantity = sum(quantity, na.rm = TRUE)) %>%
arrange(week)
ggplot(quantity_by_week, aes(x = week, y = total_quantity)) +
geom_line(color = "blue", size = 1) +
geom_point(color = "orange", size = 2) +
labs(title = "Total Quantity Purchased by Week",
x = "Week Number",
y = "Total Quantity Purchased") +
theme_minimal()
## 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.

sales_by_home_ownership <- trans_and_demog %>%
group_by(home_ownership) %>%
summarise(total_sales_value = sum(sales_value, na.rm = TRUE),
average_sales_value = mean(sales_value, na.rm = TRUE)) %>%
filter(!is.na(home_ownership))
ggplot(sales_by_home_ownership, aes(x = home_ownership, y = total_sales_value, fill = home_ownership)) +
geom_bar(stat = "identity") +
labs(title = "Total Sales Value by Home Ownership",
x = "Home Ownership",
y = "Total Sales Value") +
theme_minimal()
