︠dc3651a1-49cf-4b34-ba8e-a549d9194e85︠ %r library("stringr") library("reshape2") library("plyr") library("ggplot2") library("MASS") library("xtable") if (!file.exists("deaths.rds")) { ## from https://github.com/hadley/mexico-mortality/raw/master/deaths/deaths08.csv.bz2 deaths <- read.csv("deaths08.csv.bz2") unlink("deaths08.csv.bz2") deaths$hod[deaths$hod == 99] <- NA deaths$hod[deaths$hod == 24] <- 0 deaths$hod[deaths$hod == 0] <- NA deaths$hod <- as.integer(deaths$hod) deaths <- arrange(deaths, yod, mod, dod, hod, cod) deaths <- deaths[c("yod", "mod", "dod", "hod", "cod")] saveRDS(deaths, "deaths.rds") } deaths <- readRDS("deaths.rds") ok <- subset(deaths, yod == 2008 & mod != 0 & dod != 0) xtable(ok[c(1, 1:14 * 2000), c("yod", "mod", "dod", "hod", "cod")], "raw.tex") codes <- read.csv("icd-main.csv") codes$disease <- sapply(codes$disease, function(x) str_c(strwrap(x, width = 30),collapse = "\n")) names(codes)[1] <- "cod" codes <- codes[!duplicated(codes$cod), ] # Display overall hourly deaths hod_all <- subset(count(deaths, "hod"), !is.na(hod)) qplot(hod, freq, data = hod_all, geom = "line") + scale_y_continuous("Number of deaths", labels = function(x) format(x, big.mark = ",")) + xlab("Hour of day") ︡2128738f-18ba-488f-81d1-e2b3e1b095a2︡{"html":"
yod | mod | dod | hod | cod | |
---|---|---|---|---|---|
11938 | 2008 | 1 | 1 | 1 | B20 |
13937 | 2008 | 1 | 2 | 4 | I67 |
15937 | 2008 | 1 | 3 | 8 | I50 |
17937 | 2008 | 1 | 4 | 12 | I50 |
19937 | 2008 | 1 | 5 | 16 | K70 |
21937 | 2008 | 1 | 6 | 18 | I21 |
23937 | 2008 | 1 | 7 | 20 | I21 |
25937 | 2008 | 1 | 8 | NA | K74 |
27937 | 2008 | 1 | 10 | 5 | K74 |
29937 | 2008 | 1 | 11 | 9 | I21 |
31937 | 2008 | 1 | 12 | 15 | I25 |
33937 | 2008 | 1 | 13 | 20 | R54 |
35937 | 2008 | 1 | 15 | 2 | I61 |
37937 | 2008 | 1 | 16 | 7 | I21 |
39937 | 2008 | 1 | 17 | 13 | I21 |