Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diegovalle/mxmaps
An R package for making maps of Mexico
https://github.com/diegovalle/mxmaps
map mexico r r-package rstats
Last synced: about 1 month ago
JSON representation
An R package for making maps of Mexico
- Host: GitHub
- URL: https://github.com/diegovalle/mxmaps
- Owner: diegovalle
- License: other
- Created: 2016-01-03T23:09:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-02T01:14:52.000Z (6 months ago)
- Last Synced: 2024-08-06T03:05:01.315Z (5 months ago)
- Topics: map, mexico, r, r-package, rstats
- Language: R
- Homepage: https://www.diegovalle.net/mxmaps/
- Size: 8.56 MB
- Stars: 75
- Watchers: 9
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
title: "Mexico Choropleths"
author: "Diego Valle-Jones"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
output:
github_document:
toc: true
fig_width: 8
fig_height: 5
---Master: [![R build status](https://github.com/diegovalle/mxmaps/workflows/R-CMD-check/badge.svg)](https://github.com/diegovalle/mxmaps/actions)
[![Coverage Status](https://coveralls.io/repos/github/diegovalle/mxmaps/badge.svg?branch=master)](https://coveralls.io/github/diegovalle/mxmaps?branch=master)| | |
|--------------|--------------------------------------------------------------------------|
| __Author:__ | Diego Valle-Jones |
| __License:__ | [BSD_3](https://opensource.org/licenses/BSD-3-Clause) |
| __Website:__ | [https://www.diegovalle.net/mxmaps/](https://www.diegovalle.net/mxmaps/) |
| __Forum:__ | [Google Group](https://groups.google.com/forum/#!forum/mxmaps) |## What does it do?
This package is based on [choroplethr](https://CRAN.R-project.org/package=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](https://CRAN.R-project.org/package=inegiR), and format strings so they match the INEGI state and municipio codes. Be sure to visit the [official website](https://www.diegovalle.net/mxmaps/).
```{r setup, include=FALSE}
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:
```r
if (!require(devtools)) {
install.packages("devtools")
}
devtools::install_github('diegovalle/mxmaps')
```## Quick Example
```{r}
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.
```{r}
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):
```{r}
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")```