knitr::opts_chunk$set(echo = TRUE, 
                      fig.dim = c(6, 4), 
                      dpi = 200, 
                      out.width = '100%')

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.

library(mxmaps)
library(ggplot2)
# Insert token here
# If you don't have a token you can get one from:
# https://www.inegi.org.mx/app/api/indicadores/interna_v1_1/tokenVerify.aspx
token <- ""
if (identical(token, ""))
  token <- Sys.getenv("INEGI_TOKEN")

```r mxc_regions <- subset(df_mxmunicipio_2020, 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\nZona Metropolitana del Valle de México", caption = "Data source: INEGI BISE (Banco de Indicadores)")

state_regions <- df_mxstate_2020$region choropleth_inegi(token, state_regions, indicator = "6200240365", legend = "%", title = "Porcentaje de la población de 15 años y más\ncon instrucción superior") hexbin_inegi(token, state_regions, indicator = "1007000014", legend = "número", title = "Huelgas estalladas")



diegovalle/mxmaps documentation built on Sept. 22, 2023, 9:57 p.m.