library(sf)
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library(ggplot2)
list.files("C:/Users/alima/Downloads/51.71_Kota_Denpasar")
## [1] "51.71_kecamatan.geojson" "51.71_kelurahan.geojson"
## [3] "51.71_Kota_Denpasar.geojson" "README.txt"
## [5] "Visualisasi-data.html" "Visualisasi-data.Rmd"
## [7] "Visualisasi data.Rmd"
setwd("C:/Users/alima/Downloads/51.71_Kota_Denpasar")
# 1. Baca data GeoJSON
kota <- st_read("51.71_Kota_Denpasar.geojson")
## Reading layer `51.71_Kota_Denpasar' from data source
## `C:\Users\alima\Downloads\51.71_Kota_Denpasar\51.71_Kota_Denpasar.geojson'
## using driver `GeoJSON'
## Simple feature collection with 1 feature and 3 fields
## Geometry type: MULTIPOLYGON
## Dimension: XYZ
## Bounding box: xmin: 115.1725 ymin: -8.752372 xmax: 115.2749 ymax: -8.591519
## z_range: zmin: 0 zmax: 0
## Geodetic CRS: WGS 84
kecamatan <- st_read("51.71_kecamatan.geojson")
## Reading layer `51.71_kecamatan' from data source
## `C:\Users\alima\Downloads\51.71_Kota_Denpasar\51.71_kecamatan.geojson'
## using driver `GeoJSON'
## Simple feature collection with 4 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XYZ
## Bounding box: xmin: 115.1725 ymin: -8.752372 xmax: 115.2749 ymax: -8.591519
## z_range: zmin: 0 zmax: 0
## Geodetic CRS: WGS 84
kelurahan <- st_read("51.71_kelurahan.geojson")
## Reading layer `51.71_kelurahan' from data source
## `C:\Users\alima\Downloads\51.71_Kota_Denpasar\51.71_kelurahan.geojson'
## using driver `GeoJSON'
## Simple feature collection with 43 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XYZ
## Bounding box: xmin: 115.1725 ymin: -8.752372 xmax: 115.2749 ymax: -8.591519
## z_range: zmin: 0 zmax: 0
## Geodetic CRS: WGS 84
# 2. Plot 1: Batas wilayah Kota Denpasar
ggplot() +
geom_sf(data = kota, fill = "lightblue", color = "black") +
ggtitle("Batas Wilayah Kota Denpasar") +
theme_minimal()

# 3. Plot 2: Peta Kecamatan dengan warna berbeda
ggplot() +
geom_sf(data = kecamatan, aes(fill = as.factor(nm_kecamatan)), color = "white") +
ggtitle("Kecamatan di Kota Denpasar") +
scale_fill_brewer(palette = "Set2", name = "Kecamatan") +
theme_minimal()

names(kelurahan)
## [1] "kd_propinsi" "kd_dati2" "kd_kecamatan" "kd_kelurahan" "nm_kelurahan"
## [6] "geometry"
head(st_drop_geometry(kelurahan))
## kd_propinsi kd_dati2 kd_kecamatan kd_kelurahan nm_kelurahan
## 1 51 71 002 014 Penatih
## 2 51 71 003 001 Padangsambian Kelod
## 3 51 71 001 001 Serangan
## 4 51 71 003 005 Dauh Puri
## 5 51 71 001 009 Sanur Kaja
## 6 51 71 002 005 Kesiman Kertalangu
# 4. Plot 3: Peta Kelurahan dengan warna acak
ggplot() +
geom_sf(data = kelurahan, aes(fill = as.factor(nm_kelurahan)), color = "grey40") +
ggtitle("Kelurahan di Kota Denpasar") +
theme_minimal() +
guides(fill = guide_legend(title = "Kelurahan"))
