knitr::opts_chunk$set(echo = TRUE, fig.dim = c(6, 6), dpi = 100, out.width = '100%')
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) or municipios ("01001", "01002", etc) either as strings 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, some example data.frames, such as df_mxstate_2020
and df_mxmunicipio_2020
, are provided with demographic variables from the 2020 Census.
library(mxmaps) library(htmlTable) data("df_mxstate_2020") htmlTable(head(df_mxstate_2020), rnames = FALSE, col.rgroup = c("none", "#F7F7F7")) data("df_mxmunicipio_2020") htmlTable(head(df_mxmunicipio_2020), rnames = FALSE, col.rgroup = c("none", "#F7F7F7"))
There are additional data.frames with data from other censuses or conteos intercensales
data("df_mxstate_2015") htmlTable(head(df_mxstate_2015), rnames = FALSE, col.rgroup = c("none", "#F7F7F7")) data("df_mxmunicipio_2015") htmlTable(head(df_mxmunicipio_2015), rnames = FALSE, col.rgroup = c("none", "#F7F7F7"))
data("df_mxstate_1990_2010") htmlTable(head(df_mxstate_1990_2010), rnames = FALSE, col.rgroup = c("none", "#F7F7F7")) data("df_mxmunicipio_1990_2010") htmlTable(head(df_mxmunicipio_1990_2010), rnames = FALSE, col.rgroup = c("none", "#F7F7F7"))
State names and abbreviations come in two versions since normal people always use Veracruz instead of its full official name of Veracruz de Ignacio de la Llave, and it's kind of awkward to use the Chiapas official abbreviation of Chis.
library("geojsonio") # Convert the topoJSON to spatial object data(mxstate.topoJSON) tmpdir <- tempdir() # have to use RJSONIO or else the topojson isn't valid write(RJSONIO::toJSON(mxstate.topoJSON), file.path(tmpdir, "state.topojson")) states <- topojson_read(file.path(tmpdir, "state.topojson"))
str_mxstate(c(32, 5)) str_mxmunicipio(c(32, 5), c(9, 18)) str_mxmunicipio(c(32001, 5009))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.