enadol / mxmaps

An R package to create Mexico choropleths

Home Page:https://www.diegovalle.net/mxmaps/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mexico Choropleths

Diego Valle-Jones February 11, 2016

Master: Travis-CI Build Status Develop: Travis-CI Build Status Coverage Status

Author: Diego Valle-Jones
License: BSD_3
Status: alpha
Website: https://www.diegovalle.net/mxmaps/

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.

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")
df_mxstate$value <- df_mxstate$pop
mxstate_choropleth(df_mxstate,
                    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 and df_mxmunicipio, are provided with demographic variables from the Encuesta Intercensal 2015.

data("df_mxstate")
knitr::kable(head(df_mxstate))
region state_name state_name_official state_abbr state_abbr_official pop pop_male pop_female afromexican part_afromexican indigenous part_indigenous
01 Aguascalientes Aguascalientes AGS Ags. 1312544 640091 672453 653 4559 153395 18716
02 Baja California Baja California BC BC 3315766 1650341 1665425 7445 10432 283055 38391
03 Baja California Sur Baja California Sur BCS BCS 712029 359137 352892 11032 5132 103034 11728
04 Campeche Campeche CAMP Camp. 899931 441276 458655 3554 6833 400811 13140
05 Coahuila Coahuila de Zaragoza COAH Coah. 2954915 1462612 1492303 2761 8137 204890 28588
06 Colima Colima COL Col. 711235 350791 360444 762 3314 145297 12373
data("df_mxmunicipio")
knitr::kable(head(df_mxmunicipio))
region state_code state_name state_name_official state_abbr state_abbr_official municipio_code municipio_name pop pop_male pop_female afromexican part_afromexican indigenous part_indigenous metro_area
01001 01 Aguascalientes Aguascalientes AGS Ags. 001 Aguascalientes 877190 425731 451459 532 2791 104125 14209 Aguascalientes
01002 01 Aguascalientes Aguascalientes AGS Ags. 002 Asientos 46464 22745 23719 3 130 1691 92 NA
01003 01 Aguascalientes Aguascalientes AGS Ags. 003 Calvillo 56048 27298 28750 10 167 7358 2223 NA
01004 01 Aguascalientes Aguascalientes AGS Ags. 004 Cosío 15577 7552 8025 0 67 2213 191 NA
01005 01 Aguascalientes Aguascalientes AGS Ags. 005 Jesús María 120405 60135 60270 32 219 8679 649 Aguascalientes
01006 01 Aguascalientes Aguascalientes AGS Ags. 006 Pabellón de Arteaga 46473 22490 23983 3 74 6232 251 NA

Municipios

Here's another example of Mexican municipios (similar to counties):

data("df_mxmunicipio")
df_mxmunicipio$value <-  df_mxmunicipio$indigenous / df_mxmunicipio$pop 
mxmunicipio_choropleth(df_mxmunicipio, num_colors = 1,
                       title = "Percentage of the population that self-identifies as indigenous")

About

An R package to create Mexico choropleths

https://www.diegovalle.net/mxmaps/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:R 100.0%