Skip to content

Instantly share code, notes, and snippets.

Avatar

Diego Valle-Jones diegovalle

View GitHub Profile
@diegovalle
diegovalle / mx_grid.R
Last active Jun 17, 2021
mexico geofacet
View mx_grid.R
library(dplyr)
library(stringr)
library(readr)
library(ggplot2)
library(geofacet)
options(stringsAsFactors = FALSE)
mx_grid <- data.frame(
code = c(2L, 8L, 26L, 3L, 5L, 10L, 19L, 25L, 28L, 1L, 18L, 24L, 32L,
11L, 13L, 14L, 22L, 30L, 6L, 15L, 29L, 9L, 17L, 21L, 31L, 4L,
@diegovalle
diegovalle / censo_2020.sh
Last active Mar 21, 2021
Download the shapefiles from the 2020 Mexican census
View censo_2020.sh
#!/usr/bin/env bash
####################################################
# Make sure `rename` is available on your system
####################################################
# Exit on error, undefined and prevent pipeline errors,
# use '|| true' on commands that intentionally exit non-zero
set -euo pipefail
# The directory from which the script is running
readonly LOCALDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
readonly TARGET_DIR="$LOCALDIR/censo2020"
@diegovalle
diegovalle / key.asc
Last active Feb 16, 2021
PGP PUBLIC KEY - Diego Valle-Jones
View key.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFNoG6gBEADUb3F7iVz7k6yt5oVipTv4F0kg6SUoBEPcU/sSwwu40XLyDRm2
fVOgdsr5lWYTpcq4JWOk7S27IOTknZpWMNetdb3XHHdATWoHSEln3acIvZWQxmQ8
nJFIKfgM4WbWBPQMFXs9KU5FrBJC/iETzlgv7yFfvp1eBfz57fUNAE3ZQ496du9w
VPiXscN7Q49KCz/V/QE59agiokEbLpnVC2q8kjM+ydjSjEUNTvqwJPBek6KQDkHT
rHiEw/JKA+/P3FrDdp2LFtLpKmbgOviqV1+2GtQE16qjA0FfsoA3pK9wJeu21Qtv
vajY+Oe864TFkOJG/fO07RzsTfqA63FfDPtm+s/j18OcISab1DPk6guEmTOTqEsB
RAUMUiMyu7HawCSob6vwYrNsRlU6S/KFnC2AlWOfpBStq1tiEbqo/fGn2I84744o
J6eCyP15qG0NbFt+tF53iEMRVPG+VH40v1nymPbe5xUdcvj6kv/1A46PM0zBmM60
@diegovalle
diegovalle / README.md
Last active Oct 3, 2020
Topojson of Mexican municipalities and states
View README.md

How to create the topojson map:

curl -o estados.zip http://mapserver.inegi.org.mx/MGN/mge2010v5_0.zip
curl -o  municipios.zip http://mapserver.inegi.org.mx/MGN/mgm2010v5_0.zip
unzip estados.zip 
unzip municipios.zip
ogr2ogr states.shp Entidades_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
ogr2ogr municipalities.shp Municipios_2010_5.shp -t_srs "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
topojson -o mx_tj.json -s 1e-7 -q 1e5 states.shp municipalities.shp -p state_code=+CVE_ENT,state_name=NOM_ENT,mun_code=+CVE_MUN,mun_name=NOM_MUN
@diegovalle
diegovalle / download-mapa-digital.sh
Last active Jun 11, 2020
Download the shapefiles contained in the Mapa Digital de México
View download-mapa-digital.sh
#! /bin/bash
# Author: Diego Valle-Jones
# Web: http://www.diegovalle.net
# Purpose: Download the shapefiles contained in the Mapa Digital de México
# comunicaciones y transportes
# cultura
# curvas de nivel
# hidrografia
@diegovalle
diegovalle / mapa_covid.R
Created Apr 15, 2020
Mapa de casos COVID-19
View mapa_covid.R
## Auto-Install the following packages
.packs <- c("tidyverse", "lubridate", "ggrepel", "viridis", "scales")
.success <- suppressWarnings(sapply(.packs, require, character.only = TRUE))
if (length(names(.success)[!.success])) {
install.packages(names(.success)[!.success])
sapply(names(.success)[!.success], require, character.only = TRUE)
}
if (!require(mxmaps))
devtools::install_github("diegovalle/mxmaps")
library(mxmaps)
@diegovalle
diegovalle / mx_geofacet.R
Last active May 22, 2020
Mexico geofacet
View mx_geofacet.R
library(dplyr)
library(readr)
library(ggplot2)
library(geofacet)
read_csv("https://data.diegovalle.net/elcrimen/nm-estatal-victimas.csv.gz") %>%
filter(subtipo == "HOMICIDIO DOLOSO") %>%
group_by(subtipo, state_code, state, date) %>%
summarise(count = sum(count, na.rm = TRUE),
View leyenda_colores_mxmaps.R
library("ggplot2")
library("mxmaps")
df_mxmunicipio$value <- as.factor(sample(letters[1:2], 2457, replace = TRUE) )
df_mxmunicipio$value <- factor(df_mxmunicipio$value, levels = c("a", "b",
"c", "d"))
gg = MXMunicipioChoropleth$new(df_mxmunicipio)
gg$title <- "Municipios a and b"
gg$set_num_colors(4)
gg$ggplot_scale <- scale_fill_manual("type",
View cumsum.R
## Auto-Install the following packages
.packs <- c("ggplot2", "tabulizer", "dplyr", "stringr",
"rvest", "hrbrthemes", "scales", "tidyr",
"lubridate", "directlabels")
.success <- suppressWarnings(sapply(.packs, require, character.only = TRUE))
if (length(names(.success)[!.success])) {
install.packages(names(.success)[!.success])
sapply(names(.success)[!.success], require, character.only = TRUE)
}
View download_mapa_digital.sh
#! /bin/bash
# Projection compatible with Google Maps
PROJECTION="+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0"
# wget command
WGET="wget -w 5 --random-wait --tries=2 -nc"
# The mapa digital is available as 4 files
declare -a extensions=(".exe" "-1.bin" "-2.bin" "-3.bin")
$WGET "http://internet.contenidos.inegi.org.mx/contenidos/productos/prod_serv/contenidos/espanol/bvinegi/productos/nueva_estruc/promo/Instalador_proy_bas_inf_2017.zip" -O md.zip