::install_github("yutannihilation/ggsflabel")
remoteslibrary(tidyverse)
library(sf)
library(ggspatial)
library(ggplot2)
library(prettymapr)
library(ggsflabel)
IPM NTB
Package
Memanggil data
<- st_read("C:\\Users\\User\\Documents\\Peta\\Nusatenggarabarat\\ntb.shp") ntb
Reading layer `ntb' from data source
`C:\Users\User\Documents\Peta\Nusatenggarabarat\ntb.shp' using driver `ESRI Shapefile'
Simple feature collection with 10 features and 7 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 115.821 ymin: -9.109656 xmax: 119.3462 ymax: -8.080054
Geodetic CRS: WGS 84
<- read.csv("C:\\Users\\User\\Documents\\Data\\Tingkat_IPM_NTB.csv", sep = ";", header = T)
ipm ipm
No kab_kota_ IPM.Literasi
1 1 Lombok Barat 46,34
2 2 Lombok Tengah 41,94
3 3 Lombok Timur 44,4
4 4 Sumbawa 53,3
5 5 Dompu 54,1
6 6 Bima 41,2
7 7 Sumbawa Barat 70,6
8 8 Lombok Utara 61,2
9 9 Kota Mataram 69,38
10 10 Kota Bima 65,48
Visualisasi Statis
%>%
ntb ggplot() +
geom_sf() +
::geom_sf_label_repel(aes(label = str_wrap(kab_kota, width = 10)), size = 3) +
ggsflabeltheme_bw() +
theme(axis.title = element_blank())
Visualisasi Statis OSM
<- ntb %>% st_transform(3857)
ntb_osm st_crs(ntb_osm)$proj4string
[1] "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"
%>% ggplot()+
ntb_osm annotation_map_tile(type = "osm", zoomin = 0)+
geom_sf()+
::geom_sf_label_repel(aes(label= str_wrap(kab_kota,width = 1)),
ggsflabelsize=1.75)+theme_bw()
Join Data
<- ntb %>% full_join(y=ipm, by= join_by(kab_kota==kab_kota_))
dat dat
Simple feature collection with 11 features and 9 fields (with 1 geometry empty)
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 115.821 ymin: -9.109656 xmax: 119.3462 ymax: -8.080054
Geodetic CRS: WGS 84
First 10 features:
kode_kk kode_pro kab_kota provinsi fid
1 52.05 52 Dompu Nusa Tenggara Barat 52.05
2 52.07 52 Sumbawa Barat Nusa Tenggara Barat 52.07
3 52.08 52 Lombok Utara Nusa Tenggara Barat 52.08
4 52.06 52 Bima Nusa Tenggara Barat 52.06
5 52.71 52 Kota Mataram Nusa Tenggara Barat 52.71
6 52.72 52 Kota Bima Nusa Tenggara Barat 52.72
7 52.04 52 Sumbawa Nusa Tenggara Barat 52.04
8 52.01 52 Lombok Barat Nusa Tenggara Barat 52.01
9 52.02 52 Lombok Tengah Nusa Tenggara Barat 52.02
10 52.03 52 Lombok Timur Nusa Tenggara Barat 52.03
nama
1 Kabupaten Dompu
2 Kabupaten Sumbawa Barat
3 Kabupaten Lombok Utara
4 Kabupaten Bima
5 Kota Mataram
6 Kota Bima
7 Kabupaten Sumbawa
8 Kabupaten Lombok Barat
9 Kabupaten Lombok Tengah
10 Kabupaten Lombok Timur
label No IPM.Literasi
1 Kabupaten Dompu, Provinsi Nusa Tenggara Barat, 52.05 5 54,1
2 Kabupaten Sumbawa Barat, Provinsi Nusa Tenggara Barat, 52.07 7 70,6
3 Kabupaten Lombok Utara, Provinsi Nusa Tenggara Barat, 52.08 8 61,2
4 Kabupaten Bima, Provinsi Nusa Tenggara Barat, 52.06 6 41,2
5 Kota Mataram, Provinsi Nusa Tenggara Barat, 52.71 9 69,38
6 Kota Bima, Provinsi Nusa Tenggara Barat, 52.72 10 65,48
7 Kabupaten Sumbawa, Provinsi Nusa Tenggara Barat, 52.04 4 53,3
8 Kabupaten Lombok Barat, Provinsi Nusa Tenggara Barat, 52.01 1 46,34
9 Kabupaten Lombok Tengah, Provinsi Nusa Tenggara Barat, 52.02 NA <NA>
10 Kabupaten Lombok Timur, Provinsi Nusa Tenggara Barat, 52.03 3 44,4
geometry
1 MULTIPOLYGON (((118.2471 -8...
2 MULTIPOLYGON (((116.8428 -9...
3 MULTIPOLYGON (((116.1349 -8...
4 MULTIPOLYGON (((118.5021 -8...
5 MULTIPOLYGON (((116.107 -8....
6 MULTIPOLYGON (((118.7275 -8...
7 MULTIPOLYGON (((117.0503 -9...
8 MULTIPOLYGON (((115.9482 -8...
9 MULTIPOLYGON (((116.188 -8....
10 MULTIPOLYGON (((116.4463 -8...
Visualisasi Statis dari Data
# Replace commas with dots and convert to numeric
$IPM.Literasi <- as.numeric(gsub(",", ".", dat$IPM.Literasi))
dat# Filter out rows with empty geometries
<- dat[!st_is_empty(dat$geometry), ]
dat <- st_transform(dat, crs = 32650) # Replace with appropriate CRS if needed
dat
# Create the plot
<- dat %>%
p0 ggplot() +
geom_sf(aes(fill = IPM.Literasi)) +
::geom_sf_label_repel(aes(label = str_wrap(kab_kota, width = 10)), size = 1.75) +
ggsflabelscale_fill_viridis_c(option = "magma", direction = -1, breaks = seq(30, 70, 10)) +
annotation_north_arrow(location = "tl", which_north = "true",
pad_x = unit(0.2, "cm"), pad_y = unit(0.2, "cm"),
style = north_arrow_nautical, width = unit(1.5, "cm"),
height = unit(1.5, "cm")) +
theme_bw() +
theme(axis.title = element_blank())
# Show plot
p0
<- dat %>%
p1 ggplot()+
annotation_map_tile(type = "osm", zoomin = 0)+
geom_sf(aes(fill = IPM.Literasi)) +
::geom_sf_label_repel(aes(label = str_wrap(kab_kota, width = 10)), size = 1.75) +
ggsflabelscale_fill_stepsn(colours = viridis::magma(n=6, direction = -1),breaks = seq(30, 70, 10))+
annotation_north_arrow(location = "tl", which_north = "true",
pad_x = unit(0.2, "cm"), pad_y = unit(0.2, "cm"),
style = north_arrow_nautical, width = unit(1.5, "cm"),
height = unit(1.5, "cm")) +
theme_bw() +
theme(axis.title = element_blank())
p1
Loading required namespace: raster
Zoom: 9
Visualisasi Interaktif
%>% mapview::mapview(zcol="IPM.Literasi",
dat at= seq(30,70,10),
col.regions= viridis::magma(n=7, direction = -1))