First Plot
totsal <- promotions_sample %>%
filter(display_location == 7) %>%
inner_join(transactions, by = "product_id") %>%
group_by(product_id) %>%
summarize(total_sales = sum(sales_value))
totsal %>%
slice_max(order_by = total_sales, n = 10) %>%
ggplot(aes(product_id, total_sales)) +
geom_col(fill = "darkorange", color = "black") +
labs(title = "Top 10 Products vs. Sales",
subtitle = "Total sales for the top 10 products displayed in-aisle",
x = "Products",
y = "Total Sales ($)")

Second Plot
tot_pick <- products %>%
filter(str_detect(product_type, regex('pickles', 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))
tot_pick %>%
ggplot(aes(Month, total_sales)) +
coord_cartesian(ylim = c(0, 60)) +
geom_col(fill = "lightgreen", color = "darkgreen") +
labs(title = "Total Pickle Sales by Month",
x = "Month",
y = "Total Sales ($)")

Third Plot
plot_three <- transactions_sample %>%
inner_join(products) %>%
inner_join(demographics)
ggplot(plot_three, aes(x = quantity, y = sales_value)) +
geom_point() +
facet_grid(~ age) +
geom_point(color = "firebrick") +
theme(plot.background = element_rect(fill = 'grey')) +
theme(plot.margin = unit(c(1,1,1,1), "cm")) +
theme(axis.text.x = element_text(angle = 50, size = 5, vjust = 0.5)) +
labs(title = "Sales by Age Ranges", subtitle = "Total sales by quantity across all age ranges", x = "Quantity", y = "Sales Value")
