-
Notifications
You must be signed in to change notification settings - Fork 26
/
README.Rmd
74 lines (55 loc) · 3.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
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")
```