Load required packages

library(tidyverse) library(lubridate) library(scales)

Load the data (assuming you have already created bike_orderlines_wrangled_tbl)

If you saved it as RDS:

bike_orderlines_wrangled_tbl <- readRDS(‘./bike_orderlines.rds’)

Or if you need to recreate it, run the data wrangling code first

===================================================================

Plot 1: Total Sales Revenue by Year

===================================================================

sales_by_year <- bike_orderlines_wrangled_tbl %>% mutate(order_date = ymd(order_date), year = year(order_date)) %>% group_by(year) %>% summarise(total_revenue = sum(total_price)) %>% ungroup()

plot1 <- ggplot(sales_by_year, aes(x = factor(year), y = total_revenue)) + geom_col(fill = “#667eea”, alpha = 0.8) + geom_text(aes(label = scales::dollar(total_revenue)), vjust = -0.5, size = 4) + scale_y_continuous(labels = scales::dollar_format()) + labs(title = “Total Sales Revenue by Year”, subtitle = “Annual revenue trends from 2015-2019”, x = “Year”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot1)

===================================================================

Plot 2: Sales Revenue by Category (Primary)

===================================================================

sales_by_category <- bike_orderlines_wrangled_tbl %>% group_by(category_1) %>% summarise(total_revenue = sum(total_price)) %>% ungroup() %>% arrange(desc(total_revenue))

plot2 <- ggplot(sales_by_category, aes(x = reorder(category_1, total_revenue), y = total_revenue, fill = category_1)) + geom_col(show.legend = FALSE) + geom_text(aes(label = scales::dollar(total_revenue, scale = 1e-6, suffix = “M”)), hjust = -0.1, size = 4) + scale_y_continuous(labels = scales::dollar_format(), expand = expansion(mult = c(0, 0.1))) + scale_fill_brewer(palette = “Set2”) + coord_flip() + labs(title = “Total Sales Revenue by Product Category”, subtitle = “Mountain bikes lead in total revenue”, x = “Category”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot2)

===================================================================

Plot 3: Monthly Sales Trend Over Time

===================================================================

monthly_sales <- bike_orderlines_wrangled_tbl %>% mutate(order_date = ymd(order_date), year_month = floor_date(order_date, “month”)) %>% group_by(year_month) %>% summarise(monthly_revenue = sum(total_price)) %>% ungroup()

plot3 <- ggplot(monthly_sales, aes(x = year_month, y = monthly_revenue)) + geom_line(color = “#667eea”, size = 1.2) + geom_point(color = “#667eea”, size = 2) + geom_smooth(method = “loess”, se = TRUE, color = “#764ba2”, alpha = 0.2) + scale_y_continuous(labels = scales::dollar_format()) + scale_x_date(date_breaks = “6 months”, date_labels = “%b %Y”) + labs(title = “Monthly Sales Revenue Trend”, subtitle = “Sales patterns from 2015 to 2019 with trend line”, x = “Month”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12), axis.text.x = element_text(angle = 45, hjust = 1))

print(plot3)

===================================================================

Plot 4: Sales by Secondary Category (Top 10)

===================================================================

sales_by_category2 <- bike_orderlines_wrangled_tbl %>% group_by(category_2) %>% summarise(total_revenue = sum(total_price)) %>% ungroup() %>% arrange(desc(total_revenue)) %>% slice(1:10)

plot4 <- ggplot(sales_by_category2, aes(x = reorder(category_2, total_revenue), y = total_revenue)) + geom_col(fill = “#764ba2”, alpha = 0.8) + geom_text(aes(label = scales::dollar(total_revenue, scale = 1e-6, suffix = “M”)), hjust = -0.1, size = 3.5) + scale_y_continuous(labels = scales::dollar_format(), expand = expansion(mult = c(0, 0.1))) + coord_flip() + labs(title = “Top 10 Sub-Categories by Revenue”, subtitle = “Elite Road and Trail bikes are top performers”, x = “Sub-Category”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot4)

===================================================================

Plot 5: Sales by State (Top 10)

===================================================================

sales_by_state <- bike_orderlines_wrangled_tbl %>% group_by(state) %>% summarise(total_revenue = sum(total_price), total_orders = n()) %>% ungroup() %>% arrange(desc(total_revenue)) %>% slice(1:10)

plot5 <- ggplot(sales_by_state, aes(x = reorder(state, total_revenue), y = total_revenue)) + geom_col(aes(fill = total_revenue), show.legend = FALSE) + geom_text(aes(label = scales::dollar(total_revenue, scale = 1e-6, suffix = “M”)), hjust = -0.1, size = 3.5) + scale_y_continuous(labels = scales::dollar_format(), expand = expansion(mult = c(0, 0.1))) + scale_fill_gradient(low = “#667eea”, high = “#764ba2”) + coord_flip() + labs(title = “Top 10 States by Revenue”, subtitle = “Geographic distribution of sales”, x = “State”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot5)

===================================================================

Plot 6: Revenue by Frame Material

===================================================================

sales_by_material <- bike_orderlines_wrangled_tbl %>% group_by(frame_material) %>% summarise(total_revenue = sum(total_price), avg_price = mean(price)) %>% ungroup() %>% arrange(desc(total_revenue))

plot6 <- ggplot(sales_by_material, aes(x = reorder(frame_material, total_revenue), y = total_revenue, fill = frame_material)) + geom_col(show.legend = FALSE) + geom_text(aes(label = scales::dollar(total_revenue, scale = 1e-6, suffix = “M”)), hjust = -0.1, size = 4) + scale_y_continuous(labels = scales::dollar_format(), expand = expansion(mult = c(0, 0.1))) + scale_fill_brewer(palette = “Set3”) + coord_flip() + labs(title = “Sales Revenue by Frame Material”, subtitle = “Carbon bikes generate highest revenue”, x = “Frame Material”, y = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot6)

===================================================================

Plot 7: Heatmap of Sales by Category and Year

===================================================================

sales_heatmap <- bike_orderlines_wrangled_tbl %>% mutate(order_date = ymd(order_date), year = year(order_date)) %>% group_by(category_1, year) %>% summarise(total_revenue = sum(total_price)) %>% ungroup()

plot7 <- ggplot(sales_heatmap, aes(x = factor(year), y = category_1, fill = total_revenue)) + geom_tile(color = “white”) + geom_text(aes(label = scales::dollar(total_revenue, scale = 1e-6, suffix = “M”)), color = “white”, size = 4, fontface = “bold”) + scale_fill_gradient(low = “#667eea”, high = “#764ba2”, labels = scales::dollar_format()) + labs(title = “Sales Revenue Heatmap: Category × Year”, subtitle = “Revenue distribution across categories over time”, x = “Year”, y = “Category”, fill = “Revenue”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12))

print(plot7)

===================================================================

Plot 8: Price Distribution by Category

===================================================================

plot8 <- ggplot(bike_orderlines_wrangled_tbl, aes(x = category_1, y = price, fill = category_1)) + geom_boxplot(show.legend = FALSE, alpha = 0.7) + scale_y_continuous(labels = scales::dollar_format()) + scale_fill_brewer(palette = “Set2”) + labs(title = “Price Distribution by Category”, subtitle = “Mountain bikes have highest price variance”, x = “Category”, y = “Price”) + theme_minimal() + theme(plot.title = element_text(size = 16, face = “bold”), plot.subtitle = element_text(size = 12), axis.text.x = element_text(angle = 45, hjust = 1))

print(plot8)

===================================================================

Save all plots

===================================================================

Uncomment to save plots

ggsave(“plot1_sales_by_year.png”, plot1, width = 10, height = 6)

ggsave(“plot2_sales_by_category.png”, plot2, width = 10, height = 6)

ggsave(“plot3_monthly_trend.png”, plot3, width = 12, height = 6)

ggsave(“plot4_top_subcategories.png”, plot4, width = 10, height = 6)

ggsave(“plot5_top_states.png”, plot5, width = 10, height = 6)

ggsave(“plot6_frame_material.png”, plot6, width = 10, height = 6)

ggsave(“plot7_heatmap.png”, plot7, width = 10, height = 6)

ggsave(“plot8_price_distribution.png”, plot8, width = 10, height = 6)