This package also has special functions to download and map data from the INEGI API using the inegiR package

Note: For the INEGI API to work you'll need to install the development version of inegiR

if (!require("devtools")) install.packages("devtools")
devtools::install_github("Eflores89/inegiR", upgrade = "never")
  1. You must have a token to use this functionality. It's free and easy to get by visiting the INEGI website
  2. The function plots the most recent value provided by the API
  3. You'll have to lookup the indicator code at the INEGI

the data can take a while to download and by defaut the choropleth functions will show you an estimate of how much time is remaining for the downloads to finish. If you do not want this behavior set the silent parameter to TRUE. Note that only indicators that provide data at the national and state level are supported.

# Insert token here
# If you don't have a token you can get one from:
token <- ""
mxc_regions <- subset(df_mxmunicipio, metro_area == "Valle de México")$region
choropleth_inegi(token, mxc_regions, 
                 indicator = "1002000011", 
                 silent = FALSE,
                 legend = "Edad"
                 ) +
  labs(title = "Edad Mediana Hombres en la Zona Metropolitana del Valle de México",
          caption = "Data source: INEGI BISE (Banco de Indicadores)")
Downloading data from the INEGI API

state_regions <- df_mxstate$region
choropleth_inegi(token, state_regions, 
                 indicator = "6200240365",
                 legend = "%",
                 title = "Porcentaje de la población de 15 años y más con instrucción superior")
Downloading data from the INEGI API

hexbin_inegi(token, state_regions, 
             indicator = "1007000014",
             legend = "número",
             title = "Huelgas estalladas")
Downloading data from the INEGI API