library(leaflet)
library(sf)
## Linking to GEOS 3.12.2, GDAL 3.8.5, PROJ 9.4.0; sf_use_s2() is TRUE
library(rgdal)
## Loading required package: sp
## Please note that rgdal will be retired during October 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-7, (SVN revision 1203)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.8.5, released 2024/04/02
## Path to GDAL shared files: /usr/share/gdal
## GDAL does not use iconv for recoding strings.
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 9.4.0, March 1st, 2024, [PJ_VERSION: 940]
## Path to PROJ shared files: /home/dragon/.local/share/proj:/usr/share/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:2.1-4
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
# Load the downloaded GADM data for Kenya
kenya_data <- readRDS("gadm36_KEN_2_sf.rds")
kenya_data
## Simple feature collection with 301 features and 13 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 33.90959 ymin: -4.720417 xmax: 41.92622 ymax: 5.061166
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## Geodetic CRS: WGS 84
## First 10 features:
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## GID_0 NAME_0 GID_1 NAME_1 NL_NAME_1 GID_2 NAME_2 VARNAME_2
## 1 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.1_1 805 <NA>
## 2 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.2_1 Baringo Central <NA>
## 3 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.3_1 Baringo North <NA>
## 4 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.4_1 Baringo South <NA>
## 5 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.5_1 Eldama Ravine <NA>
## 6 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.6_1 Mogotio <NA>
## 7 KEN Kenya KEN.1_1 Baringo <NA> KEN.1.7_1 Tiaty <NA>
## 81 KEN Kenya KEN.2_1 Bomet <NA> KEN.2.1_1 Bomet Central <NA>
## 82 KEN Kenya KEN.2_1 Bomet <NA> KEN.2.2_1 Bomet East <NA>
## 83 KEN Kenya KEN.2_1 Bomet <NA> KEN.2.3_1 Chepalungu <NA>
## NL_NAME_2 TYPE_2 ENGTYPE_2 CC_2 HASC_2
## 1 <NA> Constituency Constituency 162 <NA>
## 2 <NA> Constituency Constituency 159 <NA>
## 3 <NA> Constituency Constituency 158 <NA>
## 4 <NA> Constituency Constituency 160 <NA>
## 5 <NA> Constituency Constituency 162 <NA>
## 6 <NA> Constituency Constituency 161 <NA>
## 7 <NA> Constituency Constituency 157 <NA>
## 81 <NA> Constituency Constituency 197 <NA>
## 82 <NA> Constituency Constituency 196 <NA>
## 83 <NA> Constituency Constituency 195 <NA>
## geometry
## 1 MULTIPOLYGON (((35.87727 -0...
## 2 MULTIPOLYGON (((35.80651 0....
## 3 MULTIPOLYGON (((35.81394 0....
## 4 MULTIPOLYGON (((36.25757 0....
## 5 MULTIPOLYGON (((35.84734 -0...
## 6 MULTIPOLYGON (((36.10672 0....
## 7 MULTIPOLYGON (((35.67241 1....
## 81 MULTIPOLYGON (((35.31016 -0...
## 82 MULTIPOLYGON (((35.35149 -0...
## 83 MULTIPOLYGON (((35.26193 -1...
# Create the leaflet map
leaflet() %>%
addTiles() %>%
addPolygons(data = kenya_data,
color = "blue",
weight = 1,
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 0.5,
popup = ~paste("Province:", NAME_1, "<br>", "County:", NAME_2)) %>%
addLegend(position = "bottomright", colors = c("blue"), labels = c("Counties"), title = "Kenya Map")
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()
## old-style crs object detected; please recreate object with a recent sf::st_crs()