First Graph
merged_data_1 <- coupons %>%
inner_join(products, by = "product_id")
summary_data_1 <- merged_data_1 %>%
group_by(department) %>%
summarize(num_coupons = n()) %>%
arrange(desc(num_coupons)) %>%
slice_max(order_by = num_coupons, n = 10)
ggplot(summary_data_1, aes(x = reorder(department, num_coupons), y = num_coupons, fill = department)) +
geom_bar(stat = "identity") +
labs(title = "Top 10 Departments with Most Coupons",
x = "Department",
y = "Number of Coupons") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
axis.text.y = element_text(angle = 45, hjust = 1),
legend.position = "none") +
coord_flip() +
scale_fill_brewer(palette = "Set3")

Second Graph
grocery_transactions <- transactions %>%
inner_join(products, by = "product_id") %>%
filter(department == "GROCERY")
merged_data_2 <- grocery_transactions %>%
inner_join(demographics, by = "household_id")
summary_data_2 <- merged_data_2 %>%
mutate(week = as.integer(format(transaction_timestamp, "%U"))) %>%
group_by(week, kids_count) %>%
summarize(num_transactions = n())
ggplot(summary_data_2, aes(x = week, y = num_transactions, color = factor(kids_count))) +
geom_line(size = 1.2) +
geom_point(size = 2) +
xlim(0, 52) +
scale_color_brewer(palette = "Set1") +
labs(title = "Total Grocery Department items sold per Week",
subtitle="Sorted on the amount of kids the Customers have",
x = "Week",
y = "Number of Items Purchased",
color = "Number of Kids") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
axis.title = element_text(size = 14),
axis.text = element_text(size = 12),
legend.title = element_text(size = 12),
legend.text = element_text(size = 10)
)

Third Graph
transactions <- transactions %>%
left_join(products, by = "product_id") %>%
left_join(promotions_sample, by = "product_id")
summary_data_3 <- transactions %>%
group_by(display_location, product_category) %>%
summarise(total_purchases = n()) %>%
ungroup() %>%
arrange(display_location, desc(total_purchases))
store_front_data <- summary_data_3 %>%
filter(display_location == "1") %>%
top_n(10, total_purchases)
ggplot(store_front_data, aes(x = reorder(product_category, total_purchases), y = total_purchases, fill = product_category)) +
geom_bar(stat = "identity") +
coord_flip() +
scale_fill_brewer(palette = "Paired") +
labs(title = " Top 10 Purchased Product Catagories
Displayed at the Store Front", x = "Product Category", y = "Total Purchases") +
theme_minimal() +
theme(legend.position = "none")
