df <- read.csv("C:/Users/ACER A314/Documents/DATABASE REKAP DATA PEMILIH.csv",
               sep = ";",
               skip = 5,        # skip 5 baris awal
               header = FALSE,
               stringsAsFactors = FALSE)

# Lihat dulu isinya
View(df)
head(df)
##   V1            V2 V3 V4   V5    V6    V7   V8   V9  V10  V11  V12  V13  V14
## 1                  NA NA    L     P   L+P    L    P  L+P    L    P  L+P    L
## 2  1       ASAKOTA  6 47  41    48    89    1    5    6   27   19   46   10 
## 3  2        MPUNDA 10 45  39    37    76    7    9   16   11    8   19   21 
## 4  3          RABA 11 54  61   104   165   14   12   26   31   20   51   35 
## 5  4 RASANAE BARAT  6 42  25    40    65    4    4    8   27   10   37    6 
## 6  5 RASANAE TIMUR  8 30  47    80   127    9    3   12   17   10   27   15 
##    V15  V16 V17 V18  V19  V20  V21  V22   V23   V24   V25   V26
## 1    P  L+P   L   P  L+P    L    P  L+P     L     P   L+P      
## 2   7   17   5   3    8   14   22   36    98   104   202  0,79%
## 3  10   31   4   2    6   22   18   40   104    84   188  0,78%
## 4  16   51   1   8    9   19   45   64   161   205   366  1,25%
## 5   7   13   1   2    3   11   23   34    74    86   160  0,74%
## 6  16   31   9   7   16   27   45   72   124   161   285  2,01%
# Hapus baris 1 yang isinya header sisa (NA NA L P L+P dst)
df <- df[-1, ]

# Beri nama kolom yang jelas
colnames(df) <- c("NO", "KELURAHAN", "JML_KEL", "JML_TPS",
                  "FISIK_L", "FISIK_P", "FISIK_LP",
                  "INTELEKTUAL_L", "INTELEKTUAL_P", "INTELEKTUAL_LP",
                  "MENTAL_L", "MENTAL_P", "MENTAL_LP",
                  "WICARA_L", "WICARA_P", "WICARA_LP",
                  "RUNGU_L", "RUNGU_P", "RUNGU_LP",
                  "NETRA_L", "NETRA_P", "NETRA_LP",
                  "TOTAL_L", "TOTAL_P", "TOTAL_LP",
                  "PERSEN_DISABILITAS")

# Reset nomor baris
rownames(df) <- NULL

# Ubah kolom angka dari character ke numeric
kolom_angka <- c("NO", "JML_KEL", "JML_TPS",
                 "FISIK_L", "FISIK_P", "FISIK_LP",
                 "INTELEKTUAL_L", "INTELEKTUAL_P", "INTELEKTUAL_LP",
                 "MENTAL_L", "MENTAL_P", "MENTAL_LP",
                 "WICARA_L", "WICARA_P", "WICARA_LP",
                 "RUNGU_L", "RUNGU_P", "RUNGU_LP",
                 "NETRA_L", "NETRA_P", "NETRA_LP",
                 "TOTAL_L", "TOTAL_P", "TOTAL_LP")

df[kolom_angka] <- lapply(df[kolom_angka], as.numeric)
## Warning in lapply(df[kolom_angka], as.numeric): NAs introduced by coercion
# Cek hasil akhir
head(df)
##   NO     KELURAHAN JML_KEL JML_TPS FISIK_L FISIK_P FISIK_LP INTELEKTUAL_L
## 1  1       ASAKOTA       6      47      41      48       89             1
## 2  2        MPUNDA      10      45      39      37       76             7
## 3  3          RABA      11      54      61     104      165            14
## 4  4 RASANAE BARAT       6      42      25      40       65             4
## 5  5 RASANAE TIMUR       8      30      47      80      127             9
## 6 NA                    41     218     213     309      522            35
##   INTELEKTUAL_P INTELEKTUAL_LP MENTAL_L MENTAL_P MENTAL_LP WICARA_L WICARA_P
## 1             5              6       27       19        46       10        7
## 2             9             16       11        8        19       21       10
## 3            12             26       31       20        51       35       16
## 4             4              8       27       10        37        6        7
## 5             3             12       17       10        27       15       16
## 6            33             68      113       67       180       87       56
##   WICARA_LP RUNGU_L RUNGU_P RUNGU_LP NETRA_L NETRA_P NETRA_LP TOTAL_L TOTAL_P
## 1        17       5       3        8      14      22       36      98     104
## 2        31       4       2        6      22      18       40     104      84
## 3        51       1       8        9      19      45       64     161     205
## 4        13       1       2        3      11      23       34      74      86
## 5        31       9       7       16      27      45       72     124     161
## 6       143      20      22       42      93     153      246     561     640
##   TOTAL_LP PERSEN_DISABILITAS
## 1  202.000              0,79%
## 2  188.000              0,78%
## 3  366.000              1,25%
## 4  160.000              0,74%
## 5  285.000              2,01%
## 6    1.201              1,05%
str(df)
## 'data.frame':    7 obs. of  26 variables:
##  $ NO                : num  1 2 3 4 5 NA NA
##  $ KELURAHAN         : chr  "ASAKOTA" "MPUNDA" "RABA" "RASANAE BARAT" ...
##  $ JML_KEL           : num  6 10 11 6 8 41 NA
##  $ JML_TPS           : num  47 45 54 42 30 218 NA
##  $ FISIK_L           : num  41 39 61 25 47 213 NA
##  $ FISIK_P           : num  48 37 104 40 80 309 NA
##  $ FISIK_LP          : num  89 76 165 65 127 522 NA
##  $ INTELEKTUAL_L     : num  1 7 14 4 9 35 NA
##  $ INTELEKTUAL_P     : num  5 9 12 4 3 33 NA
##  $ INTELEKTUAL_LP    : num  6 16 26 8 12 68 NA
##  $ MENTAL_L          : num  27 11 31 27 17 113 NA
##  $ MENTAL_P          : num  19 8 20 10 10 67 NA
##  $ MENTAL_LP         : num  46 19 51 37 27 180 NA
##  $ WICARA_L          : num  10 21 35 6 15 87 NA
##  $ WICARA_P          : num  7 10 16 7 16 56 NA
##  $ WICARA_LP         : num  17 31 51 13 31 143 NA
##  $ RUNGU_L           : num  5 4 1 1 9 20 NA
##  $ RUNGU_P           : num  3 2 8 2 7 22 NA
##  $ RUNGU_LP          : num  8 6 9 3 16 42 NA
##  $ NETRA_L           : num  14 22 19 11 27 93 NA
##  $ NETRA_P           : num  22 18 45 23 45 153 NA
##  $ NETRA_LP          : num  36 40 64 34 72 246 NA
##  $ TOTAL_L           : num  98 104 161 74 124 561 NA
##  $ TOTAL_P           : num  104 84 205 86 161 640 NA
##  $ TOTAL_LP          : num  202 188 366 160 285 ...
##  $ PERSEN_DISABILITAS: chr  "0,79%" "0,78%" "1,25%" "0,74%" ...
# Install dan load library yang dibutuhkan
library(ggplot2)
library(tidyr)
library(dplyr)
## 
## 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
# GRAFIK 1: Total Pemilih Disabilitas per Kelurahan
# ============================================
ggplot(df, aes(x = reorder(KELURAHAN, TOTAL_LP), y = TOTAL_LP, fill = KELURAHAN)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  labs(title = "Total Pemilih Disabilitas per Kelurahan",
       x = "Kelurahan", y = "Jumlah Pemilih") +
  theme_minimal() +
  theme(legend.position = "none",
        plot.title = element_text(face = "bold", size = 14))
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_bar()`).

# ============================================
# GRAFIK 2: Perbandingan L vs P per Jenis Disabilitas
# ============================================
disabilitas_lp <- data.frame(
  Jenis = c("Fisik", "Intelektual", "Mental", "Wicara", "Rungu", "Netra"),
  Laki_laki = c(sum(df$FISIK_L, na.rm=TRUE), sum(df$INTELEKTUAL_L, na.rm=TRUE),
                sum(df$MENTAL_L, na.rm=TRUE), sum(df$WICARA_L, na.rm=TRUE),
                sum(df$RUNGU_L, na.rm=TRUE), sum(df$NETRA_L, na.rm=TRUE)),
  Perempuan = c(sum(df$FISIK_P, na.rm=TRUE), sum(df$INTELEKTUAL_P, na.rm=TRUE),
                sum(df$MENTAL_P, na.rm=TRUE), sum(df$WICARA_P, na.rm=TRUE),
                sum(df$RUNGU_P, na.rm=TRUE), sum(df$NETRA_P, na.rm=TRUE))
)

disabilitas_long <- pivot_longer(disabilitas_lp, 
                                  cols = c("Laki_laki", "Perempuan"),
                                  names_to = "Gender", values_to = "Jumlah")

ggplot(disabilitas_long, aes(x = Jenis, y = Jumlah, fill = Gender)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Laki_laki" = "#4472C4", "Perempuan" = "#ED7D31"),
                    labels = c("Laki-laki", "Perempuan")) +
  labs(title = "Perbandingan L vs P per Jenis Disabilitas",
       x = "Jenis Disabilitas", y = "Jumlah", fill = "Gender") +
  theme_minimal() +
  theme(plot.title = element_text(face = "bold", size = 14))

# ============================================
# GRAFIK 4: Overview Semua Jenis Disabilitas (Pie Chart)
# ============================================
overview <- data.frame(
  Jenis = c("Fisik", "Intelektual", "Mental", "Wicara", "Rungu", "Netra"),
  Total = c(sum(df$FISIK_LP, na.rm=TRUE), sum(df$INTELEKTUAL_LP, na.rm=TRUE),
            sum(df$MENTAL_LP, na.rm=TRUE), sum(df$WICARA_LP, na.rm=TRUE),
            sum(df$RUNGU_LP, na.rm=TRUE), sum(df$NETRA_LP, na.rm=TRUE))
)

overview$Persen <- round(overview$Total / sum(overview$Total) * 100, 1)
overview$Label <- paste0(overview$Jenis, "\n", overview$Persen, "%")

ggplot(overview, aes(x = "", y = Total, fill = Jenis)) +
  geom_bar(stat = "identity", width = 1) +
  coord_polar("y") +
  geom_text(aes(label = Label), position = position_stack(vjust = 0.5), size = 3) +
  scale_fill_brewer(palette = "Set2") +
  labs(title = "Overview Semua Jenis Disabilitas") +
  theme_void() +
  theme(plot.title = element_text(face = "bold", size = 14, hjust = 0.5),
        legend.position = "none")

# Pastikan semua library di-load di chunk pertama
library(ggplot2)
library(plotly)
## 
## 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(wordcloud2)
library(RColorBrewer)
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(dplyr)
plot_data <- df %>%
  select(KELURAHAN, FISIK_LP, INTELEKTUAL_LP, MENTAL_LP,
         WICARA_LP, RUNGU_LP, NETRA_LP, TOTAL_LP) %>%
  mutate(across(-KELURAHAN, as.numeric))

fig <- plot_ly(plot_data, x = ~KELURAHAN, y = ~FISIK_LP,
               type = "bar", name = "Fisik",
               marker = list(color = "#FF69B4")) %>%
  add_trace(y = ~INTELEKTUAL_LP, name = "Intelektual",
            marker = list(color = "#FF1493")) %>%
  add_trace(y = ~MENTAL_LP, name = "Mental",
            marker = list(color = "#DC143C")) %>%
  add_trace(y = ~WICARA_LP, name = "Wicara",
            marker = list(color = "#C71585")) %>%
  add_trace(y = ~RUNGU_LP, name = "Rungu",
            marker = list(color = "#8B0000")) %>%
  add_trace(y = ~NETRA_LP, name = "Netra",
            marker = list(color = "#FFB6C1")) %>%
  layout(title = list(text = "<b>Disabilitas per Kelurahan (Interaktif)</b>"),
         barmode = "stack",
         xaxis = list(title = "Kelurahan", tickangle = -30),
         yaxis = list(title = "Jumlah Pemilih"),
         legend = list(title = list(text = "Jenis Disabilitas")),
         plot_bgcolor = "#fff0f5",
         paper_bgcolor = "#fff0f5")

fig
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
# GRAFIK 3: WORDCLOUD Kelurahan

wc_data <- df %>%
  mutate(TOTAL_LP = as.numeric(TOTAL_LP)) %>%
  select(KELURAHAN, TOTAL_LP) %>%
  filter(!is.na(TOTAL_LP))

wordcloud2(wc_data,
           color = rep(c("#FF69B4", "#FF1493", "#DC143C", "#C71585", "#8B0000"),
                       length.out = nrow(wc_data)),
           backgroundColor = "#fff0f5",
           size = 1.2,
           fontWeight = "bold")
# GRAFIK 4: Perbandingan Total L vs P (Donut Chart)

total_gender <- data.frame(
  Gender = c("Laki-laki", "Perempuan"),
  Total = c(
    sum(as.numeric(df$TOTAL_L), na.rm = TRUE),
    sum(as.numeric(df$TOTAL_P), na.rm = TRUE)
  )
)

total_gender$Persen <- round(total_gender$Total / sum(total_gender$Total) * 100, 1)
total_gender$Label <- paste0(total_gender$Gender, "\n",
                              total_gender$Total, " (", total_gender$Persen, "%)")

ggplot(total_gender, aes(x = 2, y = Total, fill = Gender)) +
  geom_bar(stat = "identity", width = 1, color = "white", linewidth = 1) +
  coord_polar("y") +
  xlim(0.5, 2.5) +
  scale_fill_manual(values = c("Laki-laki" = "#8B0000", "Perempuan" = "#FF69B4")) +
  geom_text(aes(label = Label),
            position = position_stack(vjust = 0.5),
            color = "white", fontface = "bold", size = 4) +
  labs(title = "Perbandingan Total Pemilih Disabilitas\nLaki-laki vs Perempuan") +
  theme_void() +
  theme(plot.title = element_text(face = "bold", size = 14, hjust = 0.5),
        legend.position = "none",
        plot.background = element_rect(fill = "#fff0f5", color = NA))

Setelah di-paste, klik Knit untuk melihat hasilnya. Kirim screenshot kalau ada error ya!