Skip to content

Instantly share code, notes, and snippets.

View diegovalle's full-sized avatar

Diego Valle-Jones diegovalle

View GitHub Profile
@diegovalle
diegovalle / cumsum.R
Last active March 31, 2020 19:52
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)
}
#! /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
@diegovalle
diegovalle / shp_encuesta_intercensal_2015.sh
Last active May 20, 2019 19:26
Shapefiles from the the Encuesta Intercensal 2015
#! /bin/bash
# Author: Diego Valle-Jones
# Web: https://www.diegovalle.net
# LICENSE: Apache 2.0
# Purpose: Download shapefiles of manzanas (blocks), agebs (census areas), ejes
# viales (streets), interesting areas and a whole bunch of other stuff from
# the Encuesta Intercensal 2015
# As of now, this script has not been tested on Windows,
@diegovalle
diegovalle / download-census-shp.sh
Last active May 20, 2019 19:20
Download shapefiles at the census tract and block level for all of urban Mexico—more than 5 GB of data!
#!/bin/bash
# Author: Diego Valle-Jones
# Web: http://www.diegovalle.net
# Purpose: Download shapefiles of manzanas (blocks), agebs (census areas), ejes
# viales (streets), interesting areas and a whole bunch of other stuff
# Note that you'll need a recent version of innoextract
# http://constexpr.org/innoextract/, one that can work with files
# created by version 5.5 of Inno Setup, the one in Ubuntu universe is
# not recent enough. The version available at
library(aire.zmvm)
library(rsinaica)
library(ggplot2)
library(tidyverse)
library(lubridate)
library(zoo)
library(hrbrthemes)
pm25_2019 <- sinaica_param_data("PM2.5", "2019-05-01", "2019-05-16")
library(aire.zmvm) #devtools::install_github('diegovalle/aire.zmvm')
library(ggplot2)
library(tidyverse)
library(lubridate)
library(zoo)
library(hrbrthemes)
df <- get_station_month_data("HORARIOS", "PM25", 2019, 5)
df <- df %>%
filter(station_code %in% c("SAC", "NEZ")) %>%
library(lubridate)
library(aire.zmvm)
library(ggplot2)
library(dplyr)
library(hrbrthemes)
get_latest_imeca()
df <- get_zone_imeca("HORARIOS", "TC", "TZ", "2019-05-01", "2019-05-14")
df$datetime <- ymd_h(paste0(df$date, " ", df$hour))
@diegovalle
diegovalle / carto_electoral.sh
Last active February 5, 2019 18:15
Download electoral cartography from the INE
#!/bin/bash
# Author: Diego Valle-Jones
# Web: http://www.diegovalle.net
# Purpose: Script to download electoral shapefiles
# from http://cartografia.ife.org.mx/sige7/?distritacion=federal
set -euo pipefail
# Be sure to update this variable when the INE updates the shapefiles
DATE="13jul2016"
@diegovalle
diegovalle / README.md
Last active January 24, 2019 20:46
Projected Topojson of Mexican Municipalities

Projected topojson example of a choropleth of Mexican municipalities and states with tooltips and each municipality colored by the number of people who live there

First download the shapefiles of Mexico (AGEBs, Manzanas, Municipios, Estados, etc) 1.4GB from

http://www.diegovalle.net/projects.html#url=%23datasets

Then convert the files 'shps/national/national_municipal.shp' and 'shps/national/national_estatal.shp' to topojson with

library(rsinaica)
library(dplyr)
library(zoo)
library(gghighlight)
df_pm25 <- sinaica_param_data("PM2.5", "2018-12-23", "2019-01-02")
df_pm10 <- sinaica_param_data("PM10", "2018-12-23", "2019-01-02")
plot_top <- function(df, title = "", ylab = "", exclude = c("")) {
df_max <- df %>%