Skip to content

Instantly share code, notes, and snippets.

Last active Jun 18, 2021
What would you like to do?
Sample Code for Drawing Geo-political Zones
# 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")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment