Baca Data
library(readxl)
ntp <- read_xlsx("C:/Users/acer/Downloads/ntp.xlsx")
ntp
## # A tibble: 170 × 6
## id kode_provinsi nama_provinsi nilai_tukar_petani satuan tahun
## <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 1 11 ACEH 98.4 POIN 2019
## 2 10 21 KEP. RIAU 101. POIN 2019
## 3 100 82 MALUKU UTARA 102. POIN 2021
## 4 101 91 PAPUA BARAT 101. POIN 2021
## 5 102 94 PAPUA 102. POIN 2021
## 6 103 11 ACEH 107. POIN 2022
## 7 104 12 SUMATERA UTARA 122. POIN 2022
## 8 105 13 SUMATERA BARAT 110. POIN 2022
## 9 106 14 RIAU 144. POIN 2022
## 10 107 15 JAMBI 135. POIN 2022
## # ℹ 160 more rows
Subsetting/Filtering data ntp tahun 2023
ntp.2023 <- subset(ntp, tahun == 2023)
ntp.2023
## # A tibble: 34 × 6
## id kode_provinsi nama_provinsi nilai_tukar_petani satuan tahun
## <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 140 14 RIAU 153. POIN 2023
## 2 143 17 BENGKULU 147. POIN 2023
## 3 156 61 KALIMANTAN BARAT 139. POIN 2023
## 4 141 15 JAMBI 138. POIN 2023
## 5 159 64 KALIMANTAN TIMUR 129. POIN 2023
## 6 138 12 SUMATERA UTARA 125. POIN 2023
## 7 166 76 SULAWESI BARAT 121. POIN 2023
## 8 157 62 KALIMANTAN TENGAH 119. POIN 2023
## 9 145 19 KEP. BANGKA BELITUNG 118. POIN 2023
## 10 154 52 NUSA TENGGARA BARAT 115. POIN 2023
## # ℹ 24 more rows
Perbaikan data
library(stringr)
## Warning: package 'stringr' was built under R version 4.3.2
ntp.2023$nama_provinsi <- lapply(ntp.2023$nama_provinsi, function(x) str_to_title(x))
ntp.2023$nama_provinsi <- as.character(ntp.2023$nama_provinsi)
ntp.2023[11,3] <- "DKI Jakarta"
ntp.2023[14,3] <- "DI Yogyakarta"
colnames(ntp.2023) <- c("id", "Kode", "Provinsi", "NTP", "Satuan", "Tahun")
ntp.2023
## # A tibble: 34 × 6
## id Kode Provinsi NTP Satuan Tahun
## <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 140 14 Riau 153. POIN 2023
## 2 143 17 Bengkulu 147. POIN 2023
## 3 156 61 Kalimantan Barat 139. POIN 2023
## 4 141 15 Jambi 138. POIN 2023
## 5 159 64 Kalimantan Timur 129. POIN 2023
## 6 138 12 Sumatera Utara 125. POIN 2023
## 7 166 76 Sulawesi Barat 121. POIN 2023
## 8 157 62 Kalimantan Tengah 119. POIN 2023
## 9 145 19 Kep. Bangka Belitung 118. POIN 2023
## 10 154 52 Nusa Tenggara Barat 115. POIN 2023
## # ℹ 24 more rows
Peta konsentrasi
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(indonesia)
library(sf)
## Warning: package 'sf' was built under R version 4.3.2
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
prov <- id_map("indonesia", "provinsi")
colnames(prov) <- c("Provinsi", "geometry")
prov_merge <- merge(prov, ntp.2023, by = "Provinsi")
## old-style crs object detected; please recreate object with a recent sf::st_crs()
ggplot(prov_merge) +
geom_sf(aes(fill = `NTP`)) +
scale_fill_gradient(high = c("orange","red"), low = "#FFEDD2")+
labs(title = "NTP 2023")

Analisis Data Menggunakan Boxplot Biasa (GGPLOT)
library(ggplot2)
ggplot(data = ntp.2023, aes(y = NTP)) +
geom_boxplot(fill = "lightblue", color = "darkblue") +
theme_minimal() +
theme(axis.text.x = element_blank()) +
labs(x= "",y = "NTP (Poin)")

Histogram dan Garis Density Kernel
kepekatan <- density(ntp.2023$NTP, bw=3, kernel="epanechnikov")
hist(ntp.2023$NTP, freq=FALSE, breaks=10,
col="orange", main="", xlab="NTP (Poin)")
lines(kepekatan, col="red", lwd=2, main="", ylim=c(0, 0.09))

Normal QQ-Plot
qqnorm(ntp.2023$NTP)
qqline(ntp.2023$NTP, col = "red")

Mencari Medcouple (MC)
library(robustbase)
## Warning: package 'robustbase' was built under R version 4.3.3
mc <- mc(ntp.2023$NTP)
## The default of 'doScale' is FALSE now for stability;
## set options(mc_doScale_quiet=TRUE) to suppress this (once per session) message
mc
## [1] 0.3058568
Perbandingan Boxplot Biasa dan Adjusted Boxplot
#boxplot and adjusted boxplot
par(mfrow=c(1,2))
boxplot(ntp.2023$NTP, main='Boxplot Biasa', col = "orange")
abline(h=150.2, col="red")
abline(h=-47.75, col="blue")
library(robustbase)
adjbox(ntp.2023$NTP,main= 'Adjusted Boxplot', col = "orange")
abline(h= 165.453, col="red")
abline(h= 3.182999999,col="blue")
