library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.6.1
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.6.1
##
## 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
library(stringr)
Data <- read.table(file.choose(), header = TRUE, sep = "\t")
Data
## Provinsi Laki_laki
## 1 ACEH 71.32
## 2 SUMATERA UTARA 71.78
## 3 SUMATERA BARAT 72.10
## 4 RIAU 72.13
## 5 JAMBI 71.91
## 6 SUMATERA SELATAN 72.03
## 7 BENGKULU 71.39
## 8 LAMPUNG 72.12
## 9 KEP. BANGKA BELITUNG 71.96
## 10 KEP. RIAU 72.73
## 11 DKI JAKARTA 73.39
## 12 JAWA BARAT 72.78
## 13 JAWA TENGAH 73.36
## 14 DI YOGYAKARTA 73.73
## 15 JAWA TIMUR 72.64
## 16 BANTEN 72.62
## 17 BALI 72.72
## 18 NUSA TENGGARA BARAT 70.64
## 19 NUSA TENGGARA TIMUR 70.21
## 20 KALIMANTAN BARAT 71.84
## 21 KALIMANTAN TENGAH 71.67
## 22 KALIMANTAN SELATAN 71.97
## 23 KALIMANTAN TIMUR 73.44
## 24 KALIMANTAN UTARA 71.45
## 25 SULAWESI UTARA 71.94
## 26 SULAWESI TENGAH 69.17
## 27 SULAWESI SELATAN 71.75
## 28 SULAWESI TENGGARA 70.10
## 29 GORONTALO 69.13
## 30 SULAWESI BARAT 69.50
## 31 MALUKU 69.10
## 32 MALUKU UTARA 69.53
## 33 PAPUA BARAT 66.82
## 34 PAPUA BARAT DAYA 68.39
## 35 PAPUA 68.85
## 36 PAPUA SELATAN 66.78
## 37 PAPUA TENGAH 66.44
## 38 PAPUA PEGUNUNGAN 65.62
#histogram
ggplot(Data, aes(x = Laki_laki)) +
geom_histogram(
binwidth = 1,
boundary = 65,
fill = "blue",
color = "red"
) +
labs(
title = "Distribusi UHH Laki-laki di Indonesia Tahun 2025",
x = "UHH Laki-laki (Tahun)",
y = "Frekuensi"
) +
theme_classic() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold")
)

#boxplot
ggplot(Data, aes(x = "", y = Laki_laki)) +
geom_boxplot(fill = "gray") +
labs(
title = "Boxplot UHH Laki-laki di Indonesia Tahun 2025",
x = "",
y = "UHH Laki-laki (Tahun)"
) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold")
)

#barplot
library(stringr)
Data_Kalimantan <- Data %>%
filter(str_starts(Provinsi, "KALIMANTAN"))
ggplot(Data_Kalimantan,
aes(x = Provinsi, y = Laki_laki, fill = Provinsi)) +
geom_col() +
labs(
title = "UHH Laki-laki di Pulau Kalimantan Tahun 2025",
x = "Provinsi",
y = "UHH Laki-laki (Tahun)"
) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5, face = "bold"),
legend.position = "none"
)
