library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
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(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.4.3
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
df <- read_excel("data_retail_clean_Part27.xlsx")
country_counts <- df %>%
  count(country, sort = TRUE)
top10 <- df %>%
  count(country, sort = TRUE) %>%
  head(10)
top10 <- top10 %>%
  mutate(group = ifelse(country == "United Kingdom", "UK", "Other"))

plot_ly(
  data = top10,
  x = ~n,
  y = ~reorder(country, n),
  type = "bar",
  orientation = "h",
  color = ~group,
  colors = c("UK" = "orange", "Other" = "steelblue"),
  text = ~paste(
    "Negara:", country,
    "<br>Jumlah Transaksi:", n
  ),
  hoverinfo = "text",
  textposition = "none"
) %>%
  layout(
    title = "Top 10 Negara",
    hoverlabel = list(
      bgcolor = "black",
      font = list(color = "white")
    )
  )

Grafik menunjukkan bahwa United Kingdom memiliki jumlah transaksi yang sangat dominan dibandingkan negara lainnya. Perbedaan yang terlihat sangat signifikan ini menandakan bahwa sebagian besar aktivitas transaksi berasal dari UK. Negara-negara lain memang muncul dalam Top 10, namun kontribusinya relatif kecil jika dibandingkan dengan UK.

top10_no_uk <- top10 %>%
  filter(country != "United Kingdom")

plot_ly(
  data = top10_no_uk,
  x = ~n,
  y = ~reorder(country, n),
  type = "bar",
  orientation = "h",
  marker = list(color = "steelblue"),
  text = ~paste(
    "Negara:", country,
    "<br>Jumlah Transaksi:", n
  ),
  hoverinfo = "text",
  textposition = "none"
) %>%
  layout(
    title = "Top 10 Negara(tanpa UK)",
    hoverlabel = list(
      bgcolor = "black",
      font = list(color = "white")
    )
  )

Setelah United Kingdom dikeluarkan dari Grafik, terlihat bahwa distribusi transaksi antar negara menjadi lebih merata. Beberapa negara seperti Germany, France, dan Netherlands muncul sebagai kontributor utama di pasar internasional. Perbedaan antar negara tidak terlalu ekstrem, menunjukkan bahwa tidak ada satu negara lain yang benar-benar mendominasi seperti UK.

top10_products <- df %>%
  filter(quantity > 0, !is.na(description)) %>%
  group_by(description) %>%
  summarise(total_qty = sum(quantity)) %>%
  arrange(desc(total_qty)) %>%
  slice_head(n = 10)

plot_ly(
  top10_products,
  x = ~total_qty,
  y = ~reorder(description, total_qty),
  type = "bar",
  orientation = "h",
  text = ~paste(
    "Produk:", description,
    "<br>Total Terjual:", total_qty
  ),
  hoverinfo = "text",
  textposition = "none"
) %>%
  layout(
    title = "Top 10 Produk Terlaris",
    hoverlabel = list(
      bgcolor = "black",
      font = list(color = "white")
    )
  )
sum(top10_products$total_qty)
## [1] 467502

Grafik menunjukkan bahwa distribusi penjualan tidak merata di seluruh produk. Sebaliknya, terdapat konsentrasi penjualan yang signifikan pada beberapa produk tertentu yang memiliki jumlah pembelian jauh lebih tinggi dibandingkan produk lainnya.

Total penjualan yang dihasilkan oleh 10 produk terlaris juga menunjukkan kontribusi yang dominan terhadap keseluruhan transaksi. Hal ini mengindikasikan bahwa sebagian besar aktivitas pembelian pelanggan berfokus pada produk-produk tertentu yang memiliki tingkat permintaan tinggi.

Pola ini mencerminkan fenomena Pareto Principle (80/20), di mana sebagian kecil produk memberikan kontribusi besar terhadap total penjualan. Dengan kata lain, tidak semua produk memiliki peran yang sama dalam mendorong performa bisnis.

kesimpulan