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
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ 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)
library(ggplot2)
library(scales)
## 
## Attaching package: 'scales'
## 
## The following object is masked from 'package:purrr':
## 
##     discard
## 
## The following object is masked from 'package:readr':
## 
##     col_factor
bike_orderlines_tbl <- read_csv("/Users/zaari/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()