Fork me on GitHub

This R package can be used to easily create maps of Mexico at both the state and municipio levels. It is based on the choroplethr package and also includes functions to create interactive maps using the leaflet package, map INEGI data from its API using the inegiR package, and format strings so they match the INEGI state and municipio codes.


For the moment this package is only available from github. For the development version:

if (!require("devtools")) {

Quick Example


df_mxstate$value <- df_mxstate$pop
                   title = "Total population, by state") 

# What the data looks like
head(df_mxstate[,c("region", "value")])
##   region   value
## 1     01 1312544
## 2     02 3315766
## 3     03  712029
## 4     04  899931
## 5     05 2954915
## 6     06  711235

Basic Usage

The two basic functions of the package are mxstate_choropleth and mxmunicipio_choropleth. The data.frame that you provide to the plotting functions must have one column named region with the INEGI codes of the states or municipios and one column named value with the values to plot. You can specify a title with the title parameter and the number of buckets with the num_color parameter. If you want a continuous scale you can set the num_colors parameter equal to 1.


df_mxstate$value <-  df_mxstate$indigenous / df_mxstate$pop 
                   num_colors = 1,
                   title = "Percentage of the population that self-identifies as indigenous")


You can also plot Mexican municipios (similar to counties) with a continuous color scale set with num_colors = 1

df_mxmunicipio$value <-  df_mxmunicipio$indigenous / df_mxmunicipio$pop 
                       num_colors = 1,
                       title = "Percentage of the population that self-identifies as indigenous")

You can also subset the area to show in the choropleth by using the zoom parameter:

mxmunicipio_choropleth(df_mxmunicipio, num_colors = 1,
                       zoom = subset(df_mxmunicipio, metro_area %in% c("Valle de México",
                       title = "Percentage of the population that self-identifies as indigenous") 

You can use the show_states parameter to hide or show the state borders when making municipio choropleths.

mxmunicipio_choropleth(df_mxmunicipio, num_colors = 1,
                       zoom = c(31001:31106,30002:30212),
                       title = "Percentage of the population that self-identifies\nas indigenous in Yucatán and Veracruz",
                       show_states = FALSE)