## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----original-map, fig.alt = "Map of Nigeria with all its States"-------------
library(naijR)

map_ng()

## ----outline-map, fig.alt = "Outline map of Nigeria"--------------------------
map_ng("Nigeria")

## ----all-lga-map, fig.alt="Map of all the LGAs in Nigeria"--------------------
map_ng(lgas())

## ----south-west, warning=FALSE, fig.alt="State of the South-west geopolitical zone"----
map_ng(states(gpz = "sw"), show.text = TRUE, col = 4)

## ----singleton, warning=FALSE, fig.alt="Kebbi State"--------------------------
kk <- "Kebbi"
map_ng(kk, col = 6, title = paste(kk, "State"))

## ----dud-dataframe------------------------------------------------------------
# Create variables
ss <- states()
numStates <- length(ss)
vv <- sample(LETTERS[1:5], numStates, TRUE)

# Create a data frame and view top rows
dd <- data.frame(state = ss, letter = vv)
head(dd)

## ----df-approach, fig.alt="A choropleth map of Nigeria's states"--------------
map_ng(data = dd)

## ----vec-approach, fig.alt="Chroropleth map based on reds"--------------------
map_ng(region = states(), x = vv, col = "red", show.text = FALSE)

## ----error-map, error=TRUE----------------------------------------------------
try({
map_ng(region = states(), x = var)
})

## ----numeric-choropleth, fig.alt="Choropleth map with numeric values"---------
nn <- runif(numStates, max = 100)  # random real numbers ranging from 0 - 100
bb <- c(0, 40, 60, 100)

map_ng(
  region = states(),
  x = nn,
  breaks = bb,
  col = 'YlOrRd',
  show.text = FALSE
)

## ----good-legend, fig.alt="Choropleth map with a proper legent"---------------
map_ng(
  region = states(),
  x = nn,
  breaks = bb,
  categories = c("Low", "Medium", "High"),
  col = 3L, 
  show.text = FALSE
)

## ----pointmap, fig.alt="Mapping of points"------------------------------------
x <- c(3.000, 4.000, 6.000, 5.993, 5.444, 6.345, 5.744)
y <- c(8.000, 9.000, 9.300, 10.432, 8.472, 6.889, 9.654)

map_ng("Nigeria", x = x, y = y)

## ----out-of-bounds, error=TRUE------------------------------------------------
try({
map_ng("Kwara", x = x, y = y)
})

