Sales

Author

Yashas B K

Load Required Libraries

library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(lubridate)

Attaching package: 'lubridate'
The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(treemapify)

Load Dataset

data <- read.csv("SampleSuperstore.csv", stringsAsFactors = FALSE)

Convert Order Date to Date format

data$Order.Date <- as.Date(data$Order.Date, format="%m/%d/%Y")

1. BAR CHART: Sales by Category

sales_category <- data %>%
  group_by(Category) %>%
  summarise(Total_Sales = sum(Sales))

ggplot(sales_category, aes(x = Category, y = Total_Sales, fill = Category)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Sales by Category", x = "Category", y = "Total Sales")

2. LINE CHART: Monthly Sales Trend

monthly_sales <- data %>%
  mutate(Month = floor_date(Order.Date, "month")) %>%
  group_by(Month) %>%
  summarise(Total_Sales = sum(Sales))

ggplot(monthly_sales, aes(x = Month, y = Total_Sales)) +
  geom_line() +
  geom_point() +
  theme_minimal() +
  labs(title = "Monthly Sales Trend", x = "Month", y = "Sales")

3. TREEMAP (treemapify)

category_sales <- data %>%
  group_by(Category, Sub.Category) %>%
  summarise(Sales = sum(Sales))
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by Category and Sub.Category.
ℹ Output is grouped by Category.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(Category, Sub.Category))` for per-operation grouping
  (`?dplyr::dplyr_by`) instead.
ggplot(category_sales,
       aes(area = Sales,
           fill = Category,
           label = Sub.Category)) +
  geom_treemap() +
  geom_treemap_text(colour = "white", place = "centre") +
  labs(title = "Treemap of Sales by Category & Sub-Category")

4. SCATTER PLOT: Profit vs Sales

ggplot(data, aes(x = Sales, y = Profit, color = Category)) +
  geom_point(alpha = 0.6) +
  theme_minimal() +
  labs(title = "Profit vs Sales", x = "Sales", y = "Profit")