Master: R build status Coverage 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.

knitr::opts_chunk$set(echo = TRUE, fig.path = "man/figures/")

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") 

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))
data("df_mxmunicipio_2020")
knitr::kable(head(df_mxmunicipio_2020))

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")


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