Data Collection

# Load data
data <- read_csv("data_penjualan_sample.csv")
## Rows: 6 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): Tanggal, Produk, Kategori, Harga, Jumlah, Pembeli, Kota
## dbl (1): OrderID
## lgl (1): Total
## 
## ℹ 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.
glimpse(data)
## Rows: 6
## Columns: 9
## $ OrderID  <dbl> 1001, 1002, 1003, 1004, 1005, 1006
## $ Tanggal  <chr> "01-01-2024", "02-01-2024", "03-01-2024", "04-01-2024", "05-0…
## $ Produk   <chr> "Laptop A", "Tas Branded", "Tas Branded", "Kemeja", "-", "Sma…
## $ Kategori <chr> NA, "Fashion", "Aksesoris", NA, "Fashion", "Fashion"
## $ Harga    <chr> "15000000", "15000000", "15000000", "15000000", "Rp750.000", …
## $ Jumlah   <chr> "empat", "2", "3", "dua", "3", "empat"
## $ Total    <lgl> NA, NA, NA, NA, NA, NA
## $ Pembeli  <chr> "Budi@", "Budi@", "_anonymous_", "Andi123", "_anonymous_", "S…
## $ Kota     <chr> "Bandung", "Surabaya", "Bandung", "Bandung", "Jakarta", "Band…
# Jumlah baris dan kolom
dim(data)
## [1] 6 9

Data Cleaning

# Fungsi konversi karakter ke numerik
convert_to_numeric <- function(x) {
  x <- str_replace_all(x, "Rp|\\\\\\.", "")  # Hapus Rp dan titik
  x <- case_when(
    str_to_lower(x) == "dua" ~ "2",
    str_to_lower(x) == "tiga" ~ "3",
    str_to_lower(x) == "empat" ~ "4",
    str_to_lower(x) == "satu" ~ "1",
    TRUE ~ x
  )
  as.numeric(x)
}

Data Transformation

# Tambahkan kolom Bulan
data <- data %>%
  mutate(Bulan = month(Tanggal, label = TRUE, abbr = FALSE))

# Total penjualan per kategori
penjualan_kategori <- data %>%
  group_by(Kategori) %>%
  summarise(Total_Penjualan = sum(Total, na.rm = TRUE))

# Jumlah transaksi per kota
transaksi_kota <- data %>%
  group_by(Kota) %>%
  summarise(Jumlah_Transaksi = n())

# Total penjualan per bulan
penjualan_bulanan <- data %>%
  group_by(Bulan) %>%
  summarise(Total_Penjualan = sum(Total, na.rm = TRUE))

penjualan_kategori
## # A tibble: 3 × 2
##   Kategori  Total_Penjualan
##   <chr>               <int>
## 1 Aksesoris               0
## 2 Fashion                 0
## 3 <NA>                    0
transaksi_kota
## # A tibble: 3 × 2
##   Kota     Jumlah_Transaksi
##   <chr>               <int>
## 1 Bandung                 4
## 2 Jakarta                 1
## 3 Surabaya                1
penjualan_bulanan
## # A tibble: 1 × 2
##   Bulan   Total_Penjualan
##   <ord>             <int>
## 1 January               0

Visualisasi

# Grafik batang
ggplot(penjualan_kategori, aes(x = Kategori, y = Total_Penjualan, fill = Kategori)) +
  geom_bar(stat = "identity") +
  labs(title = "Total Penjualan per Kategori")

# Grafik lingkaran
transaksi_kota %>%
  mutate(prop = Jumlah_Transaksi / sum(Jumlah_Transaksi) * 100,
         label = paste0(Kota, " (", round(prop, 1), "%)")) %>%
  ggplot(aes(x = "", y = prop, fill = Kota)) +
  geom_col() +
  coord_polar(theta = "y") +
  labs(title = "Proporsi Transaksi per Kota") +
  theme_void()

# Grafik garis penjualan bulanan
ggplot(penjualan_bulanan, aes(x = Bulan, y = Total_Penjualan, group = 1)) +
  geom_line() +
  geom_point() +
  labs(title = "Tren Penjualan per Bulan")
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?