Skip to content

Instantly share code, notes, and snippets.

@BroVic
Last active March 3, 2023 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/b2ca38068a78d673d073c3df6f601be8 to your computer and use it in GitHub Desktop.
Save BroVic/b2ca38068a78d673d073c3df6f601be8 to your computer and use it in GitHub Desktop.
Sample Code for Drawing Geo-political Zones
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')
@Yinkaokoh
Copy link

Thanks very much

@BroVic
Copy link
Author

BroVic commented Mar 3, 2023

Thanks very much

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment