Health Worker Data in Banten Province With Spatial Data (Data Tenaga Kesehatan Provinsi Banten dengan Data Spasial
Call package to support data processing
Install the package first with install.packages(“packages name”)
“tidyverse” is designed to work together seamlessly to enhance and streamline data analysis and visualization.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
“ggplot2” is a powerful and flexible package for creating static, dynamic, and interactive visualizations. This packages is already contain in tidyverse packages, so you don’t have to call this package, if you already call tidyverse.
“viridis” is a package that contain of color palettes, but it designed to be perceptually uniform and friendly to colorblind individuals.
## Loading required package: viridisLite
“mapview” package provides an interactive map viewer for spatial data.
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
“sf” package provides a modern and efficeint way to handle spatial data by using the Simple Features (SF) standard, which is a standard for encoding spatial vector data.
## Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
Input spatial data with polygon geometry
This data contain of spatial data and GIS (Geographic Information Systems)
## Reading layer `idn_admbnda_adm2_bps_20200401' from data source
## `D:\S2\Semester 1\Sains Data\Praktikum\Sains Data Pertemuan 3\Praktikum minggu 3\Admin2Kabupaten\idn_admbnda_adm2_bps_20200401.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 522 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 95.01079 ymin: -11.00762 xmax: 141.0194 ymax: 6.07693
## Geodetic CRS: WGS 84
Check the data in “kab_indo” variable
## Simple feature collection with 522 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 95.01079 ymin: -11.00762 xmax: 141.0194 ymax: 6.07693
## Geodetic CRS: WGS 84
## First 10 features:
## Shape_Leng Shape_Area ADM2_EN ADM2_PCODE ADM2_REF ADM2ALT1EN
## 1 2.360029 0.2289681 Aceh Barat ID1107 <NA> <NA>
## 2 1.963994 0.1541359 Aceh Barat Daya ID1112 <NA> <NA>
## 3 4.590182 0.2363958 Aceh Besar ID1108 <NA> <NA>
## 4 3.287754 0.3161611 Aceh Jaya ID1116 <NA> <NA>
## 5 4.448584 0.3430383 Aceh Selatan ID1103 <NA> <NA>
## 6 4.907219 0.1534414 Aceh Singkil ID1102 <NA> <NA>
## 7 2.593385 0.1745672 Aceh Tamiang ID1114 <NA> <NA>
## 8 3.676889 0.3834894 Aceh Tengah ID1106 <NA> <NA>
## 9 3.473021 0.3374562 Aceh Tenggara ID1104 <NA> <NA>
## 10 5.037148 0.4434042 Aceh Timur ID1105 <NA> <NA>
## ADM2ALT2EN ADM1_EN ADM1_PCODE ADM0_EN ADM0_PCODE date validOn
## 1 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 2 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 3 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 4 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 5 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 6 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 7 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 8 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 9 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## 10 <NA> Aceh ID11 Indonesia ID 2019-12-20 2020-04-01
## validTo geometry
## 1 <NA> MULTIPOLYGON (((96.26836 4....
## 2 <NA> MULTIPOLYGON (((96.80559 3....
## 3 <NA> MULTIPOLYGON (((95.20544 5....
## 4 <NA> MULTIPOLYGON (((95.58431 4....
## 5 <NA> MULTIPOLYGON (((97.59461 2....
## 6 <NA> MULTIPOLYGON (((97.39178 2....
## 7 <NA> MULTIPOLYGON (((98.27612 4....
## 8 <NA> MULTIPOLYGON (((96.64762 4....
## 9 <NA> MULTIPOLYGON (((97.82461 3....
## 10 <NA> MULTIPOLYGON (((98.01772 4....
Input helath worker data in Banten province
Input the health worker data into jum_nakes variable and check with “print” function
## Rows: 8 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): nama_provinsi, nama_kabupaten_kota, satuan
## dbl (5): id, kode_provinsi, kode_kabupaten_kota, jumlah_nakesmas, tahun
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## # A tibble: 8 × 8
## id kode_provinsi nama_provinsi kode_kabupaten_kota nama_kabupaten_kota
## <dbl> <dbl> <chr> <dbl> <chr>
## 1 1 36 Banten 3601 KABUPATEN PANDEGLANG
## 2 2 36 Banten 3602 KABUPATEN LEBAK
## 3 3 36 Banten 3603 KABUPATEN TANGERANG
## 4 4 36 Banten 3604 KABUPATEN SERANG
## 5 5 36 Banten 3671 KOTA TANGERANG
## 6 6 36 Banten 3672 KOTA CILEGON
## 7 7 36 Banten 3673 KOTA SERANG
## 8 8 36 Banten 3674 KOTA TANGERANG SELATAN
## # ℹ 3 more variables: jumlah_nakesmas <dbl>, satuan <chr>, tahun <dbl>
Indonesia map visualization
Using ggplot package for plotting the map and using “theme_bw” to show the map in black and white format.
## Filtering to Banten province ######## Filter the GIS data for showing
Banten province only and input the data into “banten_kabkot”
variable.
## Simple feature collection with 8 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 105.0998 ymin: -7.016779 xmax: 106.7799 ymax: -5.807418
## Geodetic CRS: WGS 84
## Shape_Leng Shape_Area ADM2_EN ADM2_PCODE ADM2_REF ADM2ALT1EN
## 1 0.9809574 0.01341826 Kota Cilegon ID3672 <NA> <NA>
## 2 0.9453139 0.02163802 Kota Serang ID3673 <NA> <NA>
## 3 0.8348674 0.01482651 Kota Tangerang ID3671 <NA> <NA>
## 4 0.6787284 0.01343474 Kota Tangerang Selatan ID3674 <NA> <NA>
## 5 3.3469201 0.27051172 Lebak ID3602 <NA> <NA>
## 6 5.7695251 0.22734181 Pandeglang ID3601 <NA> <NA>
## 7 4.3171742 0.11986254 Serang ID3604 <NA> <NA>
## 8 2.2885028 0.08387756 Tangerang ID3603 <NA> <NA>
## ADM2ALT2EN ADM1_EN ADM1_PCODE ADM0_EN ADM0_PCODE date validOn
## 1 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 2 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 3 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 4 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 5 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 6 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 7 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 8 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## validTo geometry
## 1 <NA> MULTIPOLYGON (((105.928 -6....
## 2 <NA> MULTIPOLYGON (((106.1957 -6...
## 3 <NA> MULTIPOLYGON (((106.6872 -6...
## 4 <NA> MULTIPOLYGON (((106.6463 -6...
## 5 <NA> MULTIPOLYGON (((106.2797 -6...
## 6 <NA> MULTIPOLYGON (((105.5498 -6...
## 7 <NA> MULTIPOLYGON (((105.8577 -6...
## 8 <NA> MULTIPOLYGON (((106.6442 -6...
Show Banten province map.
banten_kabkot %>%
ggplot()+
geom_sf()+
ggsflabel::geom_sf_label_repel(aes(label=str_wrap(ADM2_EN,width = 1)),size=1.75)+
theme_bw()+
theme(axis.title = element_blank())## Warning in st_point_on_surface.sfc(data$geometry): st_point_on_surface may not
## give correct results for longitude/latitude data
######## Show Banten province in map street view.
banten_kabkot %>%
ggplot()+
annotation_map_tile(type = "osm", zoomin = 0)+
geom_sf()+
ggsflabel::geom_sf_label_repel(aes(label=str_wrap(ADM2_EN,width = 1)),size=1.75)+
theme_bw()## Warning in st_point_on_surface.sfc(data$geometry): st_point_on_surface may not
## give correct results for longitude/latitude data
## Zoom: 10
## Input health worker data into the Banten province map #########
Modificate colomn title in health worker data to equalize in GIS
data.
jum_nakes2019 <- jum_nakes %>%
mutate(nama_kabupaten_kota= nama_kabupaten_kota %>%
str_remove(pattern = "KABUPATEN ") %>%
str_to_title()
)
jum_nakes2019## # A tibble: 8 × 8
## id kode_provinsi nama_provinsi kode_kabupaten_kota nama_kabupaten_kota
## <dbl> <dbl> <chr> <dbl> <chr>
## 1 1 36 Banten 3601 Pandeglang
## 2 2 36 Banten 3602 Lebak
## 3 3 36 Banten 3603 Tangerang
## 4 4 36 Banten 3604 Serang
## 5 5 36 Banten 3671 Kota Tangerang
## 6 6 36 Banten 3672 Kota Cilegon
## 7 7 36 Banten 3673 Kota Serang
## 8 8 36 Banten 3674 Kota Tangerang Selatan
## # ℹ 3 more variables: jumlah_nakesmas <dbl>, satuan <chr>, tahun <dbl>
Combine the data
Combine the data by using full join.
banten_nakes <- banten_kabkot %>%
full_join(y = jum_nakes2019,
by = join_by(ADM2_EN==nama_kabupaten_kota))
banten_nakes## Simple feature collection with 8 features and 21 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 105.0998 ymin: -7.016779 xmax: 106.7799 ymax: -5.807418
## Geodetic CRS: WGS 84
## Shape_Leng Shape_Area ADM2_EN ADM2_PCODE ADM2_REF ADM2ALT1EN
## 1 0.9809574 0.01341826 Kota Cilegon ID3672 <NA> <NA>
## 2 0.9453139 0.02163802 Kota Serang ID3673 <NA> <NA>
## 3 0.8348674 0.01482651 Kota Tangerang ID3671 <NA> <NA>
## 4 0.6787284 0.01343474 Kota Tangerang Selatan ID3674 <NA> <NA>
## 5 3.3469201 0.27051172 Lebak ID3602 <NA> <NA>
## 6 5.7695251 0.22734181 Pandeglang ID3601 <NA> <NA>
## 7 4.3171742 0.11986254 Serang ID3604 <NA> <NA>
## 8 2.2885028 0.08387756 Tangerang ID3603 <NA> <NA>
## ADM2ALT2EN ADM1_EN ADM1_PCODE ADM0_EN ADM0_PCODE date validOn
## 1 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 2 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 3 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 4 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 5 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 6 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 7 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## 8 <NA> Banten ID36 Indonesia ID 2019-12-20 2020-04-01
## validTo id kode_provinsi nama_provinsi kode_kabupaten_kota jumlah_nakesmas
## 1 <NA> 6 36 Banten 3672 1633
## 2 <NA> 7 36 Banten 3673 1614
## 3 <NA> 5 36 Banten 3671 2224
## 4 <NA> 8 36 Banten 3674 2971
## 5 <NA> 2 36 Banten 3602 2542
## 6 <NA> 1 36 Banten 3601 1063
## 7 <NA> 4 36 Banten 3604 2279
## 8 <NA> 3 36 Banten 3603 4154
## satuan tahun geometry
## 1 ORANG 2019 MULTIPOLYGON (((105.928 -6....
## 2 ORANG 2019 MULTIPOLYGON (((106.1957 -6...
## 3 ORANG 2019 MULTIPOLYGON (((106.6872 -6...
## 4 ORANG 2019 MULTIPOLYGON (((106.6463 -6...
## 5 ORANG 2019 MULTIPOLYGON (((106.2797 -6...
## 6 ORANG 2019 MULTIPOLYGON (((105.5498 -6...
## 7 ORANG 2019 MULTIPOLYGON (((105.8577 -6...
## 8 ORANG 2019 MULTIPOLYGON (((106.6442 -6...
Visualize final data
Visualize final data and input into p0 variable. Choose the color using “viridis” package and set the map scale using “size”. Set the count of health worker by using “breaks=seq” function.
p0 <- banten_nakes %>%
ggplot()+
geom_sf(aes(fill=jumlah_nakesmas))+
ggsflabel::geom_sf_label_repel(aes(label=str_wrap(ADM2_EN,width = 1)),size=1.75)+
scale_fill_stepsn(colours = viridis::magma(n = 7,direction = -1),breaks=seq(1000,4500,by=500)) +
theme_bw()+
theme(axis.title = element_blank())
p0## Warning in st_point_on_surface.sfc(data$geometry): st_point_on_surface may not
## give correct results for longitude/latitude data
######## Visualiza the data with interactive map
banten_nakes %>%
mapview::mapview(zcol="jumlah_nakesmas",
at = seq(1000,4500, by=500),
col.regions=viridis::magma(n = 7,direction = -1))## Warning: Found less unique colors (7) than unique zcol values (8)!
## Interpolating color vector to match number of zcol values.