Sample Code for Drawing Geo-political Zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(naijR) | |
# 1. Draw plot of North-East GPZ | |
# First, get the states of interest | |
# Then, pass them to the mapping function's `region` parameter | |
ne <- states(gpz = "ne") | |
map_ng( | |
region = ne, | |
title = "North-East Geopolitical Zone", | |
fill = TRUE, | |
col = 'red' | |
) | |
# 2. Draw plot of all states but colour them by GPZ | |
# Here we first create a list of data frames, each | |
# of which has the states of a given GPZ. Then, we | |
# combine them together by their rows to make one | |
# big data frame. We do this so that we can create | |
# a column that is unique to all members of a particular | |
# GPZ. Once this is done, we send the data frame to the | |
# mapping function; this time, to the `data` parameter and | |
# the `x` parameter is for defining that column that is | |
# unique to each Zone. This is used to fill in the | |
# appropriate colours | |
gpz <- c("ne", "nw", "nc", "ss", "se", "sw") | |
stateList <- | |
lapply(gpz, function(x) { | |
data.frame(State = states(gpz = x), GPZ = toupper(x)) | |
}) | |
gpzData <- Reduce(rbind, stateList) | |
gpzData <- rbind(gpzData, c("Federal Capital Territory", "FCT")) | |
map_ng(data = gpzData, x = GPZ) | |
map_ng(data = gpzData, x = GPZ, col = 'red') | |
map_ng(data = gpzData, x = GPZ, col = "Set1") | |
# See ?RColorBrewer::display.brewer.all for additional colour schemes | |
# 3. Further reading | |
vignette('nigeria-maps') |
Thanks very much
You're welcome!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks very much