Skip to content

Repository files navigation

titleMexico Choropleths
authorDiego Valle-Jones
dateJuly 02, 2026
output
github_document
tocfig_widthfig_height
true
8
5

Master: R build statusCoverage Status

Author:Diego Valle-Jones
License:BSD_3
Website:https://www.diegovalle.net/mxmaps/
Forum:Google Group

What does it do?

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

Installation

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

if (!require(devtools)) {
install.packages("devtools")
}
devtools::install_github('diegovalle/mxmaps')

Quick Example

library(mxmaps)
data("df_mxstate_2020")
df_mxstate_2020$value<-df_mxstate_2020$pop
mxstate_choropleth(df_mxstate_2020,
title="Total population, by state"
)

plot of chunk readme-quick-example

Data

The data.frame that you provide to the plotting functions must have one column named "region" and one column named "value". The entries for "region" must match the INEGI codes for states ("01", "02", etc) and municipios ("01001", "01002", etc) either as a string with or without a leading "0" or as numerics. The functions str_mxstate and str_mxmunicipio are provided to easily format codes to the INEGI specification. Also, two example data.frames, df_mxstate_2020 and df_mxmunicipio_2020, are provided with demographic variables from the 2020 census.

data("df_mxstate_2020")
knitr::kable(head(df_mxstate_2020))
regionstate_namestate_name_officialstate_abbrstate_abbr_officialyearpoppop_malepop_femaleafromexicanindigenous_language
01AguascalientesAguascalientesAGSAgs.20201425607696683728924224252539
02Baja CaliforniaBaja CaliforniaBCBC20203769020190058918684316436249130
03Baja California SurBaja California SurBCSBCS20207984474058793925682633013581
04CampecheCampecheCAMPCamp.20209283634569394714241931991801
05CoahuilaCoahuila de ZaragozaCOAHCoah.2020314677115636691583102459765527
06ColimaColimaCOLCol.2020731391360622370769135745210
data("df_mxmunicipio_2020")
knitr::kable(head(df_mxmunicipio_2020))
state_codemunicipio_coderegionstate_namestate_name_officialstate_abbrstate_abbr_officialmunicipio_nameyearpoppop_malepop_femaleafromexicanindigenous_languagemetro_arealonglat
0100101001AguascalientesAguascalientesAGSAgs.Aguascalientes2020948990462073486917151701839Aguascalientes-102.296021.87982
0100201002AguascalientesAguascalientesAGSAgs.Asientos202051536252612627522522NA-102.089322.23832
0100301003AguascalientesAguascalientesAGSAgs.Calvillo202058250285632968726676NA-102.718821.84691
0100401004AguascalientesAguascalientesAGSAgs.Cosío2020170008292870821557NA-102.300022.36641
0100501005AguascalientesAguascalientesAGSAgs.Jesús María202012992964219657102543158Aguascalientes-102.343421.96127
0100601006AguascalientesAguascalientesAGSAgs.Pabellón de Arteaga202047646233772426948252NA-102.276522.14920

Municipios

Here's another example showing Mexican municipios (similar to counties):

data("df_mxmunicipio_2020")
df_mxmunicipio_2020$value<-df_mxmunicipio_2020$indigenous_language/df_mxmunicipio_2020$pop
mxmunicipio_choropleth(df_mxmunicipio_2020,
num_colors=1,
title="Percentage of the population that speaks\nan indigenous language"
)

plot of chunk readme-muncipios

Contributors

About

An R package for making maps of Mexico

Topics

Resources

Stars

84 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages