1 Heatmap

# Load Required Libraries
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
## 
## 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(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.3
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.4.3
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(scales)
# Load Data
data_bisnis <- read.csv("data bisnis.csv", stringsAsFactors = FALSE)

# Group & Summarize Data (Total Sales per Product_Category & Region)
sales_summary <- data_bisnis %>%
  group_by(Product_Category, Region) %>%
  summarise(Total_Sales = sum(Total_Price, na.rm = TRUE))
## `summarise()` has grouped output by 'Product_Category'. You can override using
## the `.groups` argument.
# Pivot Data for Heatmap
sales_pivot <- dcast(sales_summary, Product_Category ~ Region, value.var = "Total_Sales", fill = 0)
# Convert to long format for ggplot
sales_long <- melt(sales_pivot, id.vars = "Product_Category")

# Create Heatmap using ggplot2
ggplot(sales_long, aes(x = variable, y = Product_Category, fill = value)) +
  geom_tile() +
  geom_text(aes(label = format(round(value, 0), big.mark=".")), color = "white", size = 5) +  # Menampilkan angka dalam heatmap
  scale_fill_gradient(low = "#440154", high = "#FDE725", name = "Total Sales") +  # Mirip dengan cmap="viridis"
  labs(
    title = "Heatmap of Total Sales by Region and Product Category",
    x = "Region",
    y = "Product Category"
  ) +
  theme_minimal(base_size = 16) +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    plot.title = element_text(size = 20, face = "bold")
  )
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing

2 Scatter Plot

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.3
## Warning: package 'forcats' was built under R version 4.4.3
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ lubridate 1.9.4     ✔ stringr   1.5.1
## ✔ purrr     1.0.2     ✔ tibble    3.2.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
data_bisnis <- read.csv("data bisnis.csv", stringsAsFactors = FALSE)
ggplot(data_bisnis, aes(x = Quantity, y = Total_Price)) +
  geom_point(alpha = 0.6, color = "steelblue", size = 3) +
  labs(
    title = "Scatter Plot of Quantity vs Total Price",
    x = "Quantity Purchased",
    y = "Total Price"
  ) +
  theme_minimal(base_size = 14)

3 Bubble Chart

ggplot(data_bisnis, aes(x = Quantity, y = Total_Price, size = Unit_Price)) +
  geom_point(alpha = 0.6, color = "skyblue") +
  labs(
    title = "Bubble Chart of Quantity vs Total Price\n(Size by Unit Price)",
    x = "Quantity",
    y = "Total Price",
    size = "Unit Price"
  ) +
  theme_minimal(base_size = 14)

4 Correlation Matrix

# Load library
library(readr)
library(dplyr)
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Load data
df <- read_csv("data bisnis.csv")
## New names:
## Rows: 500 Columns: 25
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (8): Transaction_ID, Customer_ID, Product_Category, Product_ID, Region... dbl
## (15): ...1, Quantity, Unit_Price, Discount, Delivery_Time, Total_Price,... lgl
## (1): ID_HasPattern date (1): Transaction_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.
## • `` -> `...1`
# Ambil numerik
numeric_df <- select(df, where(is.numeric))

# Korelasi
cor_matrix <- cor(numeric_df, use = "pairwise.complete.obs")
## Warning in cor(numeric_df, use = "pairwise.complete.obs"): the standard
## deviation is zero
# Visualisasi

# Ubah ke long format untuk ggplot
cor_melt <- melt(cor_matrix)

# Plot heatmap
ggplot(cor_melt, aes(Var1, Var2, fill = value)) +
  geom_tile(color = "white") +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Correlation") +
  geom_text(aes(label = sprintf("%.2f", value)), size = 3) +
  theme_minimal(base_size = 12) +
  theme(
    axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1),
    axis.text.y = element_text(angle = 0, vjust = 1, hjust = 1),
    axis.title = element_blank(),
    panel.grid.major = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank()
  ) +
  ggtitle("Correlation Matrix")

5 Line Chart

library(readr)
library(ggplot2)
library(dplyr)
df <- read_csv("data bisnis.csv")
## New names:
## Rows: 500 Columns: 25
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (8): Transaction_ID, Customer_ID, Product_Category, Product_ID, Region... dbl
## (15): ...1, Quantity, Unit_Price, Discount, Delivery_Time, Total_Price,... lgl
## (1): ID_HasPattern date (1): Transaction_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.
## • `` -> `...1`
df$Transaction_Date <- as.Date(df$Transaction_Date)
df <- df %>% arrange(Transaction_Date)

# Tambahkan margin di sumbu Y (10% ruang di atas dan bawah)
ymin <- min(df$Total_Price, na.rm=TRUE) * 0.9
ymax <- max(df$Total_Price, na.rm=TRUE) * 1.1

ggplot(df, aes(x = Transaction_Date, y = Total_Price)) +
  geom_line(color = "#0073C2FF", size = 0.6) +
  geom_point(color = "#EFC000FF", size = 0.7) +
  labs(title = "Total Price per Transaction Over Time",
       x = "Transaction Date",
       y = "Total Price") +
  scale_y_continuous(limits = c(ymin, ymax), expand = c(0, 0)) +
  theme_minimal(base_size = 10) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.7, color = "#0073C2FF"),
    axis.text.x = element_text(angle = 30, hjust = 1)
  )
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

6 Area Chart

library(readr)
library(ggplot2)
library(dplyr)
df <- read_csv("data bisnis.csv")
## New names:
## Rows: 500 Columns: 25
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (8): Transaction_ID, Customer_ID, Product_Category, Product_ID, Region... dbl
## (15): ...1, Quantity, Unit_Price, Discount, Delivery_Time, Total_Price,... lgl
## (1): ID_HasPattern date (1): Transaction_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.
## • `` -> `...1`
df$Transaction_Date <- as.Date(df$Transaction_Date)
df <- df %>% arrange(Transaction_Date)

# Tambahkan margin di sumbu Y (10% ruang di atas dan bawah)
ymin <- min(df$Total_Price, na.rm=TRUE) * 0.9
ymax <- max(df$Total_Price, na.rm=TRUE) * 1.1

ggplot(df, aes(x = Transaction_Date, y = Total_Price)) +
  geom_area(fill = "#69b3a2", alpha = 0.7) +
  geom_line(color = "#0073C2FF", size = 0.6) +
  geom_point(color = "#EFC000FF", size = 0.7) +
  labs(title = "Area Chart: Total Price per Transaction",
       x = "Transaction Date",
       y = "Total Price") +
  theme_minimal(base_size = 14) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5, color = "#0073C2FF"),
    axis.text.x = element_text(angle = 30, hjust = 1)
  )