| | | |--------------|--------------------------------------------------------------------------| | Author: | Diego Valle-Jones | | License: | BSD_3 | | Website: | https://www.diegovalle.net/mxmaps/ | | Forum: | Google Group |
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.
knitr::opts_chunk$set(echo = TRUE, fig.path = "man/figures/")
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')
library(mxmaps) data("df_mxstate_2020") df_mxstate_2020$value <- df_mxstate_2020$pop mxstate_choropleth(df_mxstate_2020, title = "Total population, by state")
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)) data("df_mxmunicipio_2020") knitr::kable(head(df_mxmunicipio_2020))
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.