library(tidyverse)
library(readxl)
library(scales)
library(lubridate)
load("C:/Users/riaku/Downloads/webshop.RData")
library(readxl)
income_statement <- read_excel("C:/Users/riaku/Downloads/Income_statement.xlsx")
library(readxl)
promotions <- read_excel("C:/Users/riaku/Downloads/promotions.xlsx")
library(readxl)
prices <- read_excel("C:/Users/riaku/Downloads/Prices.xlsx")
# Basket analysis
basket_analysis <- shopping_basket %>%
left_join(purchases, by = "transactionID") %>%
mutate(
total_items = Tshirt + Mug + Hoodie + Poster,
item_variety = (Tshirt > 0) + (Mug > 0) + (Hoodie > 0) + (Poster > 0),
basket_type = case_when(
item_variety == 1 ~ "Single Item Type",
item_variety == 2 ~ "Two Item Types",
item_variety >= 3 ~ "Multi-Item"))
basket_type_summary <- basket_analysis %>%
group_by(basket_type) %>%
summarise(
n_transactions = n(),
avg_payment = mean(Payment),
avg_discount = mean(Discount) * 100,
avg_items = mean(total_items),
total_revenue = sum(Payment),
.groups = 'drop') %>%
mutate(
transaction_pct = (n_transactions / sum(n_transactions)) * 100,
revenue_pct = (total_revenue / sum(total_revenue)) * 100) %>%
arrange(desc(n_transactions))
##graphing this data
p3 <- ggplot(basket_type_summary, aes(x = basket_type, y = transaction_pct)) +
geom_col(fill = "pink") +
geom_text(aes(label = round(transaction_pct, 1)),
vjust = -0.5, size = 4) +
labs(title = "How Do Customers Shop?",
subtitle = "Single item vs multiple items",
x = "Basket Type",
y = "% of Transactions") +
scale_y_continuous(labels = function(x) paste0(x, "%"),
expand = expansion(mult = c(0, .15))) +
theme_minimal()
p3
