#histogram
library(ggplot2)
Data <- read.table(file.choose(),header = T)
Data
## Provinsi Jumlah_Kecamatan
## 1 Aceh 290
## 2 Sumatera_Utara 455
## 3 Sumatera_Barat 179
## 4 Riau 172
## 5 Jambi 144
## 6 Sumatera_Selatan 241
## 7 Bengkulu 129
## 8 Lampung 229
## 9 Kepulauan_Bangka_Belitung 47
## 10 Kepulauan_Riau 80
## 11 DKI_Jakarta 44
## 12 Jawa_Barat 627
## 13 Jawa_Tengah 576
## 14 DI_Yogyakarta 78
## 15 Jawa_Timur 666
## 16 Banten 155
## 17 Bali 57
## 18 Nusa_Tenggara_Barat 117
## 19 Nusa_Tenggara_Timur 315
## 20 Kalimantan_Barat 174
## 21 Kalimantan_Tengah 136
## 22 Kalimantan_Selatan 156
## 23 Kalimantan_Timur 105
## 24 Kalimantan_Utara 55
## 25 Sulawesi_Utara 171
## 26 Sulawesi_Tengah 178
## 27 Sulawesi_Selatan 313
## 28 Sulawesi_Tenggara 221
## 29 Gorontalo 77
## 30 Sulawesi_Barat 69
## 31 Maluku 120
## 32 Maluku_Utara 118
## 33 Papua_Barat 91
## 34 Papua_Barat_Daya 132
## 35 Papua 106
## 36 Papua_Selatan 82
## 37 Papua_Tengah 131
## 38 Papua_Pegunungan 252
ggplot(Data, aes(x = Jumlah_Kecamatan)) +
geom_histogram(
binwidth = 100, # Lebar interval 50 kecamatan per kelas
boundary = 0, # Batas bawah interval dimulai dari 0
fill = "pink",
color = "black"
) +
scale_x_continuous(
breaks = seq(0, 700, by = 100),
limits = c(0, 700) # Rentang batas sumbu X dari 0 sampai 700
) +
labs(
title = "Distribusi Jumlah Kecamatan per Provinsi di Indonesia",
x = "Jumlah Kecamatan",
y = "Frekuensi (Jumlah Provinsi)"
) +
theme_classic() +
theme(
axis.text.x = element_text(angle = 0, hjust = 0.5),
plot.title = element_text(
hjust = 0.5,
face = "bold"
)
)

#boxplot
library(ggplot2)
ggplot(Data, aes(x = "", y = Jumlah_Kecamatan)) +
geom_boxplot(fill = "pink", color = "black") +
labs(
title = "Box Plot Jumlah Kecamatan di Indonesia",
x = "",
y = "Jumlah Kecamatan"
) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold")
)

#barchat
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ lubridate 1.9.5 ✔ tibble 3.3.1
## ✔ purrr 1.2.2 ✔ tidyr 1.3.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
# Filter data khusus provinsi di Pulau Kalimantan
Data_Kalimantan <- Data %>%
filter(str_starts(Provinsi, regex("Kalimantan", ignore_case = TRUE)))
# Tampilkan data hasil filter
Data_Kalimantan
## Provinsi Jumlah_Kecamatan
## 1 Kalimantan_Barat 174
## 2 Kalimantan_Tengah 136
## 3 Kalimantan_Selatan 156
## 4 Kalimantan_Timur 105
## 5 Kalimantan_Utara 55
# Membuat Barplot / Diagram Batang
ggplot(Data_Kalimantan, aes(x = Provinsi, y = Jumlah_Kecamatan, fill = Provinsi)) +
geom_col() +
labs(
title = "Jumlah Kecamatan di Pulau Kalimantan",
x = "Provinsi",
y = "Jumlah Kecamatan"
) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5, face = "bold"),
legend.position = "none"
)
