Membuat Peta Lombok menggunakan R

koding
R
peta
Ini adalah catatan kedua saya yang memuat kode R. Kode ini dimaksudkan untuk membuat peta statis Pulau Lombok yang dapat ditampilkan di laman daring.
Penulis

Mohammad Rizki

Diterbitkan

7 Mei 2025

Kita mencoba membuat peta Pulau Lombok dengan inset Kota Mataram.

Percobaan Pertama

Lihat kode!
library(sf)
Linking to GEOS 3.13.1, GDAL 3.11.1, PROJ 9.6.2; sf_use_s2() is TRUE
Lihat kode!
library(ggplot2)
library(geodata)
Loading required package: terra
terra 1.8.54
Lihat kode!
library(cowplot)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:terra':

    intersect, union
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Lihat kode!
# Unduh data administratif level 2 (kabupaten/kota) untuk Indonesia
indo_l2 <- st_as_sf(gadm("IDN", level = 2, path = tempdir()))

# Ambil hanya wilayah Pulau Lombok (NTB)
lombok <- indo_l2 %>%
  filter(NAME_1 == "Nusa Tenggara Barat") %>%
  filter(NAME_2 %in% c("Lombok Barat", "Lombok Tengah", "Lombok Timur", "Lombok Utara", "Mataram"))

# Peta utama: seluruh Lombok
peta_lombok <- ggplot(data = lombok) +
  geom_sf(fill = "white", color = "black") +
  theme_minimal() +
  labs(title = "Peta Pulau Lombok") +
  theme(axis.text = element_blank(), axis.ticks = element_blank())

# Ekstrak hanya Kota Mataram
mataram <- lombok %>% filter(NAME_2 == "Mataram")

# Buffer sedikit agar terlihat lebih luas
bbox_mataram <- st_bbox(mataram)
bbox_mataram_expanded <- bbox_mataram + c(-0.05, -0.05, 0.05, 0.05)

# Peta inset Mataram
peta_mataram <- ggplot() +
  geom_sf(data = mataram, fill = "orange", color = "black") +
  coord_sf(xlim = c(bbox_mataram_expanded["xmin"], bbox_mataram_expanded["xmax"]),
           ylim = c(bbox_mataram_expanded["ymin"], bbox_mataram_expanded["ymax"])) +
  theme_void() +
  labs(title = "Inset: Kota Mataram") +
  theme(plot.title = element_text(size = 10))