dplyr, lubridate, ggplot2, scales, plotly, glue, kableExtra, rsconnect
# dplyr: untuk data wrangling/cleaning
library(dplyr)
heavy_part <- read.csv("data_input/heavy_part.csv")
head(data, n): tampilkan n baris
teratas.# your code
heavy_part %>%
head(5)
summary(data): tampilkan rangkuman statistik tiap kolom
di data# your code
summary(heavy_part)
#> Row.ID Order.ID Customer.ID Customer.Name
#> Min. : 1 Min. : 18 Min. :1114487 Length:27976
#> 1st Qu.: 6995 1st Qu.: 5372 1st Qu.:1114487 Class :character
#> Median :14246 Median : 5372 Median :1119087 Mode :character
#> Mean :14171 Mean : 8374 Mean :1120748
#> 3rd Qu.:21239 3rd Qu.: 7429 3rd Qu.:1129027
#> Max. :28233 Max. :31968 Max. :1129027
#> Transaksi.ID Part.Name Category Segment
#> Min. : 220301 Length:27976 Length:27976 Length:27976
#> 1st Qu.: 220602 Class :character Class :character Class :character
#> Median : 2111321115 Mode :character Mode :character Mode :character
#> Mean : 1659909822
#> 3rd Qu.: 2114521119
#> Max. :22063060002
#> Order.Date Ship.Date Cluster.Parts Quantity
#> Length:27976 Length:27976 Length:27976 Min. : 1.000
#> Class :character Class :character Class :character 1st Qu.: 5.000
#> Mode :character Mode :character Mode :character Median : 9.000
#> Mean : 7.939
#> 3rd Qu.: 9.000
#> Max. :80.000
#> Price.Per.Unit Sales Profit
#> Min. : 1.00 Min. : 2.00 Min. : 0.060
#> 1st Qu.: 4.00 1st Qu.: 27.00 1st Qu.: 0.560
#> Median : 7.00 Median : 54.00 Median : 1.080
#> Mean :10.67 Mean : 81.18 Mean : 1.762
#> 3rd Qu.:21.00 3rd Qu.:105.00 3rd Qu.: 2.100
#> Max. :21.00 Max. :880.00 Max. :26.400
heavy_part %>%
group_by(Cluster.Parts) %>%
summarise(jumlah = n()) %>%
arrange(-jumlah) %>%
mutate(proporsi = jumlah/sum(jumlah))
Cluster Parts yang paling banyak permintann adalah Control Valves dengan proporsi 34,86% dari total cluster parts yang ada.
DEEP ANALYSIS:
heavy_part %>%
group_by(Category, Segment) %>%
summarise(mean_profit = mean(Profit))
Segment part Mining dari category Belts menghasilkan rata-rata profit tertinggi, sedangkan Segment Part Compaction dari category Injectors menghasilkan rata-rata profit terendah.
Untuk setiap Segment, 3 Cluster Parts yang menghasilkan total profit paling besar?
heavy_part %>%
group_by(Cluster.Parts, Customer.Name) %>%
summarise(sum_profit = sum(Profit)) %>%
top_n(4, wt = sum_profit) %>%
arrange(Cluster.Parts, -sum_profit)
# base plot
plot(x = as.factor(heavy_part$Cluster.Parts))
library(ggplot2) # untuk plot statis
library(scales) # untuk atur skala/aestetik plot
library(glue) # untuk persiapan text di plot interaktif
library(plotly) # untuk plot interaktif
heavy_part %>%
group_by(Cluster.Parts) %>%
summarise(jumlah = n()) %>%
ggplot(aes(x = Cluster.Parts, y = jumlah)) +
geom_col(aes(fill = Cluster.Parts)) +
scale_fill_brewer(palette = "Dark2") +
labs(title = "Clustering Parts",
x = NULL, y = "Number of Clustering") +
theme_minimal() +
theme(legend.position = "none")
# plot statis
plot_bar <- heavy_part %>%
group_by(Cluster.Parts) %>%
summarise(jumlah = n()) %>%
ggplot(aes(x = Cluster.Parts, y = jumlah,
text = glue("{Cluster.Parts}
Clustering: {jumlah}"))) +
geom_col(aes(fill = Cluster.Parts)) +
scale_fill_brewer(palette = "Dark2") +
labs(title = "Clustering Parts",
x = NULL, y = "Number of Clustering") +
theme_minimal() +
theme(legend.position = "none")
# buat plot interactive
ggplotly(plot_bar, tooltip = "text")
Disclaimer: Jumlah penjualan dari data yang digunakan Hanya Ilustrasi saja, Untuk keperluan Explorasi Data!
TERIMAKASIH