1. Deskripsi Insight

Dataset yang digunakan adalah Coffee Chain Datasets yang berisi data transaksi penjualan jaringan kedai kopi. Dataset terdiri dari 4.248 baris data dengan 20 variabel yang mencakup informasi produk, lokasi, tanggal, serta data keuangan seperti penjualan (sales), keuntungan (profit), dan biaya (COGS).

Insight yang diambil: “Produk mana yang paling menguntungkan?”

Analisis ini bertujuan untuk mengidentifikasi produk dengan total profit tertinggi, membandingkan profitabilitas antar produk, serta melihat hubungan antara penjualan (sales) dan keuntungan (profit) dari setiap produk. Variabel yang digunakan dalam analisis ini adalah:


2. Import dan Persiapan Data

# Load library yang dibutuhkan
library(tidyverse)
library(readxl)
library(scales)

# Import dataset dari file Excel
df <- read_excel("Copy of 1. Tugas SIM 2025B - Coffee Chain Datasets.xlsx", sheet = "data")

# Cek struktur data
glimpse(df)
## Rows: 4,248
## Columns: 20
## $ `Area Code`      <dbl> 719, 970, 970, 303, 303, 720, 970, 719, 970, 719, 303…
## $ Date             <dttm> 2012-01-01, 2012-01-01, 2012-01-01, 2012-01-01, 2012…
## $ Market           <chr> "Central", "Central", "Central", "Central", "Central"…
## $ `Market Size`    <chr> "Major Market", "Major Market", "Major Market", "Majo…
## $ Product          <chr> "Amaretto", "Colombian", "Decaf Irish Cream", "Green …
## $ `Product Line`   <chr> "Beans", "Beans", "Beans", "Leaves", "Beans", "Beans"…
## $ `Product Type`   <chr> "Coffee", "Coffee", "Coffee", "Tea", "Espresso", "Esp…
## $ State            <chr> "Colorado", "Colorado", "Colorado", "Colorado", "Colo…
## $ Type             <chr> "Regular", "Regular", "Decaf", "Regular", "Regular", …
## $ `Budget COGS`    <dbl> 90, 80, 100, 30, 60, 80, 140, 50, 50, 40, 50, 150, 10…
## $ `Budget Margin`  <dbl> 130, 110, 140, 50, 90, 130, 160, 80, 70, 70, 70, 210,…
## $ `Budget Profit`  <dbl> 100, 80, 110, 30, 70, 80, 110, 20, 40, 20, 40, 130, 1…
## $ `Budget Sales`   <dbl> 220, 190, 240, 80, 150, 210, 300, 130, 120, 110, 120,…
## $ COGS             <dbl> 89, 83, 95, 44, 54, 72, 170, 63, 60, 58, 64, 144, 95,…
## $ Inventory        <dbl> 777, 623, 821, 623, 456, 558, 1091, 435, 336, 338, 96…
## $ Margin           <dbl> 130, 107, 139, 56, 80, 108, 171, 87, 80, 72, 76, 201,…
## $ Marketing        <dbl> 24, 27, 26, 14, 15, 23, 47, 57, 19, 22, 19, 47, 30, 7…
## $ Profit           <dbl> 94, 68, 101, 30, 54, 53, 99, 0, 33, 17, 36, 111, 87, …
## $ Sales            <dbl> 219, 190, 234, 100, 134, 180, 341, 150, 140, 130, 140…
## $ `Total Expenses` <dbl> 36, 39, 38, 26, 26, 55, 72, 87, 47, 55, 40, 90, 52, 1…
# Tampilkan ringkasan statistik variabel utama
df %>%
  select(Product, `Product Type`, Profit, Sales, Margin) %>%
  summary()
##    Product          Product Type           Profit           Sales    
##  Length:4248        Length:4248        Min.   :-638.0   Min.   : 17  
##  Class :character   Class :character   1st Qu.:  17.0   1st Qu.:100  
##  Mode  :character   Mode  :character   Median :  40.0   Median :138  
##                                        Mean   :  61.1   Mean   :193  
##                                        3rd Qu.:  92.0   3rd Qu.:230  
##                                        Max.   : 778.0   Max.   :912  
##      Margin       
##  Min.   :-302.00  
##  1st Qu.:  52.75  
##  Median :  76.00  
##  Mean   : 104.29  
##  3rd Qu.: 132.00  
##  Max.   : 613.00
# Agregasi data per produk: total profit, total sales, rata-rata margin
df_produk <- df %>% 
  group_by(Product, `Product Type`) %>%
  summarise(
  Total_Profit = sum(Profit, na.rm = TRUE),
    Total_Sales  = sum(Sales,  na.rm = TRUE),
    Avg_Margin   = mean(Margin, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  arrange(desc(Total_Profit))

# Tampilkan tabel ringkasan
df_produk
## # A tibble: 13 × 5
##    Product           `Product Type` Total_Profit Total_Sales Avg_Margin
##    <chr>             <chr>                 <dbl>       <dbl>      <dbl>
##  1 Colombian         Coffee                55804      128311      161. 
##  2 Lemon             Herbal Tea            29869       95926      109. 
##  3 Decaf Espresso    Espresso              29502       78162      106. 
##  4 Darjeeling        Tea                   29053       73151      107. 
##  5 Chamomile         Herbal Tea            27231       75578      111. 
##  6 Earl Grey         Tea                   24164       66772      128. 
##  7 Caffe Mocha       Espresso              17678       84904       93.9
##  8 Decaf Irish Cream Coffee                13989       62248       81.7
##  9 Caffe Latte       Espresso              11375       35899       91.8
## 10 Regular Espresso  Espresso              10065       24031      182. 
## 11 Mint              Herbal Tea             6154       35710       78.3
## 12 Amaretto          Coffee                 4890       26269       67.4
## 13 Green Tea         Tea                    -231       32850       43.2

3. Visualisasi Data

3.1 Total Profit per Produk

# Urutkan produk berdasarkan total profit
df_produk_sorted <- df_produk %>%
  mutate(Product = fct_reorder(Product, Total_Profit))

ggplot(df_produk_sorted, aes(x = Product, y = Total_Profit, fill = `Product Type`)) +
  geom_col(width = 0.7) +
  geom_text(aes(label = comma(Total_Profit)),
            hjust = -0.1, size = 3.2, color = "navy") +
  coord_flip() +
  scale_y_continuous(labels = comma, expand = expansion(mult = c(0, 0.15))) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title    = "Total Profit per Produk Coffee Chain",
    subtitle = "Colombian menjadi produk dengan profit tertinggi",
    x        = "Produk",
    y        = "Total Profit",
    fill     = "Tipe Produk"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    plot.title    = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "blue"),
    legend.position = "bottom"
  )

3.2 Perbandingan Total Sales vs Total Profit per Produk

# Reshape data ke format panjang untuk grouped bar chart
df_long <- df_produk_sorted %>%
  pivot_longer(cols = c(Total_Sales, Total_Profit),
               names_to = "Metrik", values_to = "Nilai") %>%
  mutate(Metrik = recode(Metrik,
                         "Total_Sales"  = "Total Sales",
                         "Total_Profit" = "Total Profit"))

ggplot(df_long, aes(x = fct_reorder(Product, Nilai), y = Nilai, fill = Metrik)) +
  geom_col(position = "dodge", width = 0.7) +
  coord_flip() +
  scale_y_continuous(labels = comma) +
  scale_fill_manual(values = c("Total Sales" = "red", "Total Profit" = "blue")) +
  labs(
    title    = "Perbandingan Total Sales dan Total Profit per Produk",
    subtitle = "Colombian unggul di keduanya; Green Tea memiliki profit negatif",
    x        = "Produk",
    y        = "Nilai",
    fill     = "Metrik"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    plot.title    = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "navy"),
    legend.position = "bottom"
  )

3.3 Rata-rata Margin per Produk

ggplot(df_produk_sorted,
       aes(x = fct_reorder(Product, Avg_Margin), y = Avg_Margin, fill = `Product Type`)) +
  geom_col(width = 0.7) +
  geom_text(aes(label = round(Avg_Margin, 1)),
            hjust = -0.1, size = 3.2, color = "navy") +
  coord_flip() +
  scale_y_continuous(expand = expansion(mult = c(0, 0.15))) +
  scale_fill_brewer(palette = "Set2") +
  labs(
    title    = "Rata-rata Margin per Produk Coffee Chain",
    subtitle = "Regular Espresso memiliki rata-rata margin tertinggi",
    x        = "Produk",
    y        = "Rata-rata Margin",
    fill     = "Tipe Produk"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    plot.title    = element_text(face = "bold", size = 14),
    plot.subtitle = element_text(color = "blue"),
    legend.position = "bottom"
  )


4. Analisis Data

4.1 Uji Statistik: Perbedaan Profit Antar Tipe Produk

Untuk menguji apakah terdapat perbedaan profit yang signifikan antar tipe produk (Coffee, Espresso, Herbal Tea, Tea), digunakan uji Kruskal-Wallis karena distribusi profit tidak diasumsikan normal.

  • H0: Tidak terdapat perbedaan profit yang signifikan antar tipe produk
  • H1: Terdapat perbedaan profit yang signifikan antar tipe produk
# Uji Kruskal-Wallis: perbedaan profit antar tipe produk
hasil_kruskal <- kruskal.test(Profit ~ `Product Type`, data = df)
hasil_kruskal
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Profit by Product Type
## Kruskal-Wallis chi-squared = 2.4137, df = 3, p-value = 0.4911
# Tampilkan p-value dan keputusan
cat("p-value:", hasil_kruskal$p.value, "\n")
## p-value: 0.491091
if (hasil_kruskal$p.value < 0.05) {
  cat("Keputusan: H0 DITOLAK — terdapat perbedaan profit yang signifikan antar tipe produk.\n")
} else {
  cat("Keputusan: H0 DITERIMA — tidak terdapat perbedaan profit yang signifikan antar tipe produk.\n")
}
## Keputusan: H0 DITERIMA — tidak terdapat perbedaan profit yang signifikan antar tipe produk.

4.2 Korelasi antara Sales dan Profit

# Uji korelasi Spearman antara Sales dan Profit
hasil_korelasi <- cor.test(df$Sales, df$Profit, method = "spearman")
hasil_korelasi
## 
##  Spearman's rank correlation rho
## 
## data:  df$Sales and df$Profit
## S = 2909365515, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.7722827
cat("Koefisien Korelasi Spearman:", round(hasil_korelasi$estimate, 4), "\n")
## Koefisien Korelasi Spearman: 0.7723
cat("p-value:", hasil_korelasi$p.value, "\n")
## p-value: 0
if (hasil_korelasi$p.value < 0.05) {
  cat("Keputusan: Terdapat hubungan yang signifikan antara Sales dan Profit.\n")
}
## Keputusan: Terdapat hubungan yang signifikan antara Sales dan Profit.

4.3 Ringkasan Profitabilitas per Tipe Produk

df %>%
  group_by(`Product Type`) %>%
  summarise(
    Total_Profit  = sum(Profit, na.rm = TRUE),
    Total_Sales   = sum(Sales,  na.rm = TRUE),
    Avg_Profit    = round(mean(Profit, na.rm = TRUE), 2),
    Avg_Margin    = round(mean(Margin, na.rm = TRUE), 2),
    .groups = "drop"
  ) %>%
  arrange(desc(Total_Profit))
## # A tibble: 4 × 5
##   `Product Type` Total_Profit Total_Sales Avg_Profit Avg_Margin
##   <chr>                 <dbl>       <dbl>      <dbl>      <dbl>
## 1 Coffee                74683      216828       70.7      115. 
## 2 Espresso              68620      222996       58.4      103. 
## 3 Herbal Tea            63254      207214       59.9      104. 
## 4 Tea                   52986      172773       55.2       94.1

5. Interpretasi Hasil

Berdasarkan analisis yang telah dilakukan, diperoleh beberapa temuan sebagai berikut:

1. Produk paling menguntungkan berdasarkan total profit:

2. Margin tertinggi bukan selalu berbanding lurus dengan profit tertinggi:

3. Hasil uji Kruskal-Wallis:

4. Korelasi Sales dan Profit:

Kesimpulan: Produk Colombian adalah produk paling menguntungkan dalam Coffee Chain ini. Strategi bisnis yang direkomendasikan adalah meningkatkan promosi dan ketersediaan produk Colombian, sekaligus mengevaluasi efisiensi biaya produk Green Tea yang mencatatkan kerugian.