Skip to content

Instantly share code, notes, and snippets.

View diegovalle's full-sized avatar

Diego Valle-Jones diegovalle

View GitHub Profile
@diegovalle
diegovalle / index.html
Last active August 29, 2015 13:56
Animated choropleth of homicide rates in Mexico 1997-2013
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://d3js.org/topojson.v1.min.js' type='text/javascript'></script>
<script src='http://datamaps.github.io/scripts/datamaps.all.min.js' type='text/javascript'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js' type='text/javascript'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js' type='text/javascript'></script>

Keybase proof

I hereby claim:

  • I am diegovalle on github.
  • I am diegovalle (https://keybase.io/diegovalle) on keybase.
  • I have a public key whose fingerprint is 76B3 74CF AFB9 E863 1313 83A8 55BD 9EC4 CD81 C252

To claim this, I am signing this object:

@diegovalle
diegovalle / religion.R
Created May 8, 2014 23:02
Education and Religion in Mexico
library(reshape)
library(ggplot2)
library(scales)
library(stringr)
hom <- read.table(text="Total,Católica,Ortodoxos,Anabautista - Menonita,Anglicana,Bautista,Iglesia del Nazareno,Luterana,Metodista,Presbiteriana,Otras protestantes,Pentecostales,Cristianas y Evangélicas sin sustento actual pentecostal,Adventistas del Séptimo Día,Iglesia de Jesucristo de los Santos de los Últimos Días (Mormones),Testigos de Jehová,Budismo,Hinduismo,Otras Orientales,Judaica,Islámica,Raíces étnicas,Espiritualistas,Otras religiones,Sin religión,No especificado
84927468,71279088,4327,7020,2908,189744,30246,2100,20464,316260,40465,1297314,4409550,492755,245641,1228239,12673,1653,1880,53880,3226,19090,29910,12343,4008693,1217999
7855312,6692152,1902,51,1010,16587,1819,972,4486,14824,8847,35932,393181,25961,36803,52871,5810,783,691,15712,1461,1662,4100,2480,454844,80371
", sep = ",", row.names=NULL, header=TRUE,
@diegovalle
diegovalle / conyugal.R
Last active August 29, 2015 14:01
Población femenina de 40 a 44 años de edad por situación conyugal
require(ggplot2)
require(reshape)
require(stringr)
require(scales)
hom <- read.table(text="Sin escolaridad Educación básica Educación media superior Educación superior Estudios técnicos o comerciales con preparatoria terminada Normal de licenciatura Profesional Maestría Doctorado
0.1333900264 0.0866986092 0.1203814875 0.1677704297 0.1350452061 0.1673361018 0.1723742877 0.2003161063 0.2381625442
0.4782996145 0.6043175271 0.6266342786 0.6165165611 0.6309864938 0.6017564164 0.6192202588 0.5912486197 0.5414840989
0.2509738821 0.1739237235 0.1075405894 0.076660514 0.0937652362 0.0858057049 0.0711621725 0.0664256176 0.0792932862
0.0728234689 0.082743796 0.0742778733 0.0565067911 0.067043598 0.0648512492 0.0533251335 0.0454456882 0.0493286219
@diegovalle
diegovalle / estudios.R
Last active August 29, 2015 14:01
Número promedio de hijos nacidos vivos por grado de estudios
require(ggplot2)
require(reshape)
require(stringr)
hom <- read.table(text="Sin escolaridad Educación básica Educación media superior Educación superior Estudios técnicos o comerciales con preparatoria terminada Normal de licenciatura Profesional Maestría Doctorado
4.3590760723 3.271073644 2.2923336285 1.8956866673 2.1159363265 1.9962284703 1.8477515858 1.655703986 1.5113780919
", sep = "\t", row.names = NULL, header=TRUE,
colClasses = "numeric")
names(hom)[1] <- "Sin.escolaridad"
@diegovalle
diegovalle / largefam.R
Last active August 29, 2015 14:01
Población femenina de 40 a 44 años de edad con 4 o más hijos nacidos vivos y que habla una lengua indígena
require(ggplot2)
require(reshape)
require(stringr)
require(scales)
library(directlabels)
hom <- read.table(text="2010 2000 state
0.589481859 0.7044360966 Total
0.4050632911 0.4418604651 Aguascalientes
0.5746496039 0.6178509532 Baja California
Verifying that +diegovalle is my Bitcoin username. You can send me #bitcoin here: https://onename.io/diegovalle
@diegovalle
diegovalle / gist:8c8ce89af5efec8d14f6
Last active August 29, 2015 14:07
rank crime cuadrantes
--cuadrantes
with crimes as
(select sum(count) as count,sector,cuadrante,max(population)as population, crime from cuadrantes where date >= '2013-08-01' and date <= '2014-07-01' group by cuadrante, sector, crime)
SELECT * from (SELECT count,crime,sector,cuadrante,rank() over (partition by crime order by count desc) as rank,population from crimes group by count,crime,sector,cuadrante,population) as temp2 where rank <= (SELECT rank from (SELECT count,cuadrante,rank() over (partition by crime order by count desc) as rank, row_number() OVER (ORDER BY count desc) AS rownum from crimes) as rank10 where rownum = 10) order by crime, rank,sector, cuadrante
--sectores
with crimes as
(select (sum(count) / (sum(population) /12 )* 100000) as rate,sum(count) as count,sector,sum(population)/12 as population, crime from cuadrantes where date >= '2013-08-01' and date <= '2014-07-01' group by sector, crime)
SELECT * from (SELECT count,rate,crime,sector,rank() over (partition by crime order by rate desc) as rank,population f
@diegovalle
diegovalle / json_to_csv.R
Last active August 29, 2015 14:08
Download the complete RNPED (https://rnped.segob.gob.mx/)
library("jsonlite")
library("dplyr")
library("magrittr")
library("stringr")
rnpe_c <- fromJSON('rnped_comun.json')
rnpe_c <- as.data.frame(rnpe_c$aaData, stringsAsFactors = FALSE)
rnpe_c$date <- as.Date(rnpe_c$fuerocomun_desapfecha, "%d/%m/%Y")
rnpe_c$tipo <- "comun"
rnpe_c$fuerocomun_desapentidad %<>% str_replace_all(" DE ZARAGOZA|ESTADO DE ", "")

Privacy Policy

Last revised on 2015-08-16

The Gist

hoyodecrimen will collect certain non-personally identify information about you as you use our sites. We may use this data to better understand our users. We can also publish this data, but the data will be about a large group of users, not individuals.

We will also ask you to provide personal information, but you'll always be able to opt out. If you give us personal information, we won't do anything evil with it.