Owing to advancements in technolgy to accurately and speedly capture geographical informtion, spatial solution have become more relevant today than ever. Understanding the role of spatial relationships on the solutions we proffer will certainly add more value to your output as a data scientist.
This assignment aims at creating a web page using R Markdown that features a map created with Leaflet.The data used for this assignment is obtained from https://mapcruzin.com/free-ghana-country-city-place-gis-shapefiles.htm. It contains the locations of cites, towns, villages, hamlets and suburbs in Ghana.
Loading libraries
suppressPackageStartupMessages({
library(rgdal)
library(leaflet)
})
Importing data
url <- "https://github.com/DLynkx/Webmaps-with-rmd-and-leaflet/raw/master/New%20Regions.zip"
if (!file.exists("./New Regions.shp") & !file.exists("./gis.osm_places_free_1")){
download.file(url,"./New_Regions.zip")
unzip("./New_Regions.zip")
}
regions <- readOGR(dsn = getwd() , layer = "New Regions", verbose = FALSE)
locations <- readOGR(dsn = getwd() , layer = "gis.osm_places_free_1", verbose = FALSE)
Regions
head(regions@data)
RGN_NM2012 Id Size_sq_Km
0 Ashanti 0 24379
1 Central 0 9666
2 Eastern 0 18988
3 Greater Accra 0 3705
4 Upper East 0 8653
5 Upper West 0 18780
Locations
head(locations@data)
osm_id code fclass population name
1 27565080 1005 national_capital 2291352 Accra
2 30748407 1010 suburb 0 Airport Residential Area
3 30748419 1010 suburb 0 Cantonments
4 30748429 1010 suburb 0 Dzorwulu
5 30748442 1010 suburb 0 Abelenkpe
6 30933189 1003 village 0 Koyni
leaflet() %>% addTiles %>% addPolygons(data = regions) %>% addCircleMarkers(data = locations, clusterOptions = markerClusterOptions(), popup = locations$name)