Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds compatibility with the 2009 ortality database

  • Loading branch information...
commit 9ffd31fbc17fa783e7e1062ad66951042135ab0a 1 parent b51ba3e
@diegovalle authored
View
0  LICENSE 100755 → 100644
File mode changed
View
10 TODO
@@ -1,4 +1,6 @@
-*Figure out the interesting municipalities,
-*Classify with a clustering algorith?
-*Convert population the data to UTF-8
-*Make it so if you unzip the SSA files they are autoloaded
+* Figure out the interesting municipalities,
+* Classify with a clustering algorith?
+* Convert population the data to UTF-8
+* Test the conversion of the SSA files
+* the function to subset the data by municipalities should
+take a strig with the state and mun as arguments
View
19 app/clean-database.R 100755 → 100644
@@ -31,28 +31,33 @@ checkFile <- function(name) {
dir <- "ssa-database/"
dbfiles <- c("BASE_DEF.DBF",
"DEF-SSA07.dbf",
- "DEF-SSA08.dbf")
+ "DEF-SSA08.DBF",
+ "SALUD09.DBF")
zipfiles <- c("def2006.zip",
"def2007.zip",
- "def2008.zip")
+ "def2008.zip",
+ "def2009.zip")
zipfiles <- paste(dir, zipfiles, sep = "")
-if(checkFile("di2008.csv") &
+if(!(checkFile("di2008.csv") &
checkFile("di2007.csv") &
- checkFile("di2006.csv")) {
+ checkFile("di2006.csv") &
+ checkFile("di2009.csv"))) {
mapply(checkFiles, zipfiles, dbfiles, dir)
#Write the csv files with all deaths
- x <- read.dbf("ssa-database/DEF-SSA08.dbf", as.is = TRUE)
+ x <- read.dbf("ssa-database/DEF-SSA08.DBF", as.is = TRUE)
write.csv(x, "data/di2008.csv", row.names = FALSE)
x <- read.dbf("ssa-database/DEF-SSA07.dbf", as.is = TRUE)
write.csv(x, "data/di2007.csv", row.names = FALSE)
- x <- read.dbf("ssa-database/BASE_DEF.dbf", as.is = TRUE)
+ x <- read.dbf("ssa-database/BASE_DEF.DBF", as.is = TRUE)
write.csv(x, "data/di2006.csv", row.names = FALSE)
-
+
+ x <- read.dbf("ssa-database/SALUD09.DBF", as.is = TRUE)
+ write.csv(x, "data/di2009.csv", row.names = FALSE)
}
View
2  app/summary-stats-functions.R
@@ -142,7 +142,7 @@ weekly <- function(hom.count, title = ""){
by="week")
ggplot(hom.w, aes(date, V1)) +
-# geom_line(color = "darkred", size = 1.2) +
+ #geom_line(color = "darkred", size = 1.2) +
geom_area(fill = "darkred") +
# geom_line(color = "darkred", size = 1.2) +
scale_x_date(minor = "month") +
View
132 app/summary-stats.R
@@ -24,40 +24,122 @@ fem <- subset(hom, SEXO == 2 & ENTOCU == 08 & MUNOCU==037)
llcharts <- generateCharts(fem, 2008, "Juárez (Females)")
saveCharts(llcharts, "juarez-femicide")
-chartRegion(hom, c(08), c(037), 2008,
- "Juárez (MA)")
+hom.j <- subset(hom, ENTOCU == 08 & MUNOCU %in% c(037))
+llcharts <- generateCharts(hom.j, 2008, "Juárez")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2008-03-28")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2008-03-28"), 60,
+ label = "J.O. Chihuahua"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "juárez (ma)")
+#chartRegion(hom, c(08), c(037), 2008,
+ # "Juárez (MA)")
+
+
chartRegion(hom, c(08), c(2, 4, 19), 2008,
"Chihuahua (MA)")
-chartRegion(hom, c(02), c(004, 003, 005), 2008,
- "Tijuana (MA)")
-chartRegion(hom, c(25), c(006), 2008,
- "Culiacán")
-chartRegion(hom, c(25), c(012), 2008,
- "Mazatlán")
-chartRegion(hom, c(12), c(001, 021), 2008,
- "Acapulco")
+chartRegion(hom, c(08), c(029), 2008,
+ "Guadalup y Calvo")
+chartRegion(hom, c(08), c(032), 2008,
+ "Hidalgo del Parral")
+chartRegion(hom, c(08), c(17), 2008,
+ "Cuauhtemoc")
+
+hom.tj <- subset(hom, ENTOCU == 02 & MUNOCU %in% c(004, 003, 005))
+llcharts <- generateCharts(hom.tj, 2008, "Tijuana")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2007-01-03")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2007-01-03"), 30,
+ label = "J.O. Tijuana"),
+ hjust = 1.03, vjust = 0) +
+ geom_vline(aes(xintercept = as.Date("2008-10-26")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2008-10-26"), 60,
+ label = "E.A.F. Captured"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "tijuana")
+#chartRegion(hom, c(02), c(004, 003, 005), 2008,
+ # "Tijuana (MA)")
+
+
+hom.cul <- subset(hom, ENTOCU == 25 & MUNOCU %in% c(006, 018))
+llcharts <- generateCharts(hom.cul, 2008, "Culiacán - Navolato")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2008-05-13")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2008-05-13"), 22,
+ label = "J.O. Culiacan-Navolato"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "culiacán")
+#chartRegion(hom, c(25), c(006), 2008,
+# "Culiacán")
+
+hom.maz <- subset(hom, ENTOCU == 25 & MUNOCU %in% c(012))
+llcharts <- generateCharts(hom.maz, 2008, "Mazatlán")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2008-07-15")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2008-07-15"), 8, label = "J.O. Culiacán - Navolato (Mazatlán)"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "mazatlán")
+#chartRegion(hom, c(25), c(012), 2008,
+ # "Mazatlán", func)
+
+hom.aca <- subset(hom, ENTOCU == 12 & MUNOCU %in% c(001, 021))
+llcharts <- generateCharts(hom.aca, 2008, "Acapulco")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2007-01-15")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2007-01-15"), 20, label = "J.O. Acapulco"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "acapulco (ma)")
+
chartRegion(hom, c(28), c(027), 2008,
"Nuevo Laredo")
chartRegion(hom, c(28), c(022), 2008,
"Matamoros (MA)")
chartRegion(hom, c(28), c(032, 033), 2008,
"Reynosa (MA)")
+
chartRegion(hom, c(26), c(043), 2008,
"Nogales")
+
chartRegion(hom, c(05), c(004, 027, 030), 2008,
"Saltillo (MA)")
-chartRegion(hom, c(15), c(053, 088), 2008,
- "Morelia (MA)")
-chartRegion(hom, c(19),
- c(6, 9, 018, 19, 21, 26, 31, 39, 45, 46, 48, 49),
- 2008,
- "Monterrey (MA)")
+chartRegion(hom, c(18), c(008, 017), 2008,
+ "Tepic (MA)")
+
+chartRegion(hom, c(16), c(053, 088), 2008,
+ "Morelia (MA)")
+hom.mon <- subset(hom, ENTOCU == 19 &
+ MUNOCU %in% c(6, 9, 018, 19, 21, 26, 31, 39,
+ 45, 46, 48, 49))
+llcharts <- generateCharts(hom.mon, 2008, "Monterrey (MA)")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2007-02-19")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2007-02-19"), 13, label = "J.O. Tamaulipas - Nuevo León"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "monterrey (ma)")
+#chartRegion(hom, c(19),
+ # c(6, 9, 018, 19, 21, 26, 31, 39, 45, 46, 48, 49),
+ # 2008,
+ # "Monterrey (MA)")
+
+hom.vall <- subset(hom, (ENTOCU == 14 & MUNOCU %in% c(067)) |
+ (ENTOCU == 18 & MUNOCU %in% c(20)))
+llcharts <- generateCharts(hom.vall, 2008, "Puerto Vallarta")
+saveCharts(llcharts, "puerto_vallarta")
chartRegion(hom, c(10), c(005), 2008,
"Durango")
+chartRegion(hom, c(10), c(032), 2008,
+ "Santiago Papasquiaro")
hom.lag <- subset(hom, (ENTOCU == 5 & MUNOCU %in% c(17,35)) |
(ENTOCU == 10 & MUNOCU %in% c(7,12)))
llcharts <- generateCharts(hom.lag, 2008, "La Laguna")
@@ -65,12 +147,26 @@ saveCharts(llcharts, "laguna")
hom.ver <- subset(hom, ENTOCU == 30)
llcharts <- generateCharts(hom.ver, 2008, "Veracruz (State)")
+llcharts$monthly <- llcharts$monthly +
+ geom_vline(aes(xintercept = as.Date("2007-05-14")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2007-05-14"), 45, label = "J.O. Veracruz"),
+ hjust = 1.1, vjust = 0)
saveCharts(llcharts, "veracruz")
hom.dur <- subset(hom, ENTOCU == 10)
llcharts <- generateCharts(hom.dur, 2008, "Durango (State)")
saveCharts(llcharts, "durango (state)")
+hom.mich <- subset(hom, ENTOCU == 16)
+llcharts <- generateCharts(hom.mich, 2008, "Michoacán (State)")
+llcharts$weekly <- llcharts$weekly +
+ geom_vline(aes(xintercept = as.Date("2006-12-11")), alpha = .7,
+ linetype = 2) +
+ geom_text(aes(as.Date("2006-12-11"), 45, label = "J.O. Michoacán"),
+ hjust = 1.03, vjust = 0)
+saveCharts(llcharts, "michoacan (state)")
+
hom.zac <- subset(hom, ENTOCU == 32)
llcharts <- generateCharts(hom.zac, 2008, "Zacatecas (State)")
saveCharts(llcharts, "zacatecas (state)")
@@ -99,8 +195,8 @@ ggplot(babies, aes(EDADVALOR, ..count.. ,group = SEXOtxt,
fill = SEXOtxt))+
geom_histogram(position = "identity", binwidth = 1, alpha = .5)
-#chartRegion(hom, c(12), c(001, 021), 2008,
-# "Lázaro Cárdenas")
+chartRegion(hom, c(16), c(52), 2008,
+ "Lázaro Cárdenas")
#It might be worthwhile to include other states, counties, and
#also presumed homicides + violent deaths of unknown intent
View
0  data/states-f.csv 100755 → 100644
File mode changed
View
0  data/states-m.csv 100755 → 100644
File mode changed
View
0  data/states.csv 100755 → 100644
File mode changed
View
7 lib/utilities.R
@@ -10,7 +10,7 @@ clean.variable.name <- function(variable.name)
clean.variable.name("2005")
#Save plots to png
-saveAAPlot <- function(p, filename, width = 800, height = 600) {
+saveAAPlot <- function(p, filename, width = 700, height = 500) {
Cairo(file = filename, width = width, height = height)
print(p)
dev.off()
@@ -144,10 +144,13 @@ saveCharts <- function(ll, location) {
}
chartRegion <- function(df, ents, muns, year,
- chart.name) {
+ chart.name, func = NULL) {
file.prefix <- tolower(chart.name)
hom.sub <- subset(df, ENTOCU %in% ents &
MUNOCU %in% muns)
ll.charts <- generateCharts(hom.sub, year, chart.name)
+ if(!is.null(func)) {
+ llcharts$weekly <- llcharts$weekly + func
+ }
saveCharts(ll.charts, file.prefix)
}
Please sign in to comment.
Something went wrong with that request. Please try again.