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)
}
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?
