library(ggplot2)
library(scales)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ lubridate 1.9.4     ✔ tibble    3.3.0
## ✔ purrr     1.1.0     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ readr::col_factor() masks scales::col_factor()
## ✖ purrr::discard()    masks scales::discard()
## ✖ 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(readxl)
library(writexl)
bikeshops_tbl <- read_excel("/Users/Frezza/Downloads/bikeshops.xlsx")
orderlines_tbl <- read_excel("/Users/Frezza/Downloads//orderlines.xlsx")
## New names:
## • `` -> `...1`
bike_orderlines_tbl <- read_csv("/Users/Frezza/Downloads//bike_orderlines.csv")
## Rows: 15644 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): model, category_1, category_2, frame_material, bikeshop_name, city...
## dbl  (5): order_id, order_line, quantity, price, total_price
## dttm (1): order_date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
revenue_by_category2 <- bike_orderlines_tbl %>%
  group_by(category_2) %>%
  summarise(revenue = sum(total_price, na.rm = TRUE)) %>%
  arrange(desc(revenue))

# 2. Plot with ggplot2
ggplot(revenue_by_category2, aes(x = revenue, 
                                 y = reorder(category_2, revenue))) +
  geom_col(fill = "blue") +
  labs(
    x = "revenue",
    y = "category_2",
    title = "Revenue by Bike Subcategory"
  ) +
  scale_x_continuous(labels = label_number()) +  # e.g. 1e+07 → 10M
  theme_minimal()