1 Konversi data

Konversi data ke format long:

library(tidyr)
data_long <- pivot_longer(data, cols = -Tahun, names_to = "Kategori", values_to = "Persen")
head(data_long, 10)
## # A tibble: 10 × 3
##    Tahun Kategori  Persen
##    <dbl> <chr>      <dbl>
##  1  2019 Preventif   16.8
##  2  2019 Obat        15.9
##  3  2019 Kuratif     67.4
##  4  2020 Preventif   19.3
##  5  2020 Obat        16.4
##  6  2020 Kuratif     64.4
##  7  2021 Preventif   27.0
##  8  2021 Obat        18.3
##  9  2021 Kuratif     54.7
## 10  2022 Preventif   27.1

2 Stacked bar plot

Membuat stacked bar plot dengan label:

library(ggplot2)
ggplot(data_long, aes(x = factor(Tahun), y = Persen, fill = Kategori)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = round(Persen, 2)), position = position_stack(vjust = 0.5)) +
  labs(title = " Distribusi Pengeluaran Kesehatan OOP \n menurut Jenis Pengeluaran Kesehatan", 
       x = "Tahun", y = "Persentase") +
  theme_minimal()


Direktorat Statistik Kesejahteraan Rakyat, BPS,