Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2013 16:04
require(ggplot2)
# load the data and cast the dob into dates
data <- read.table("/tmp/data.raw")
names(data) <- c("dob")
data$dob_date <- as.Date(as.character(data$dob), "%Y")
# build graph and preview
p = ggplot(data, aes(dob_date))
p = p + geom_density()
p = p + scale_x_date(breaks = "5 year", minor_breaks = "1 year", labels = date_format("%Y"))
p + annotate("text", x = as.Date("1952", "%Y"), y=0, label = "MauMau", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1941", "%Y"), y=0, label = "WW2", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1963", "%Y"), y=0, label = "Independence", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1982", "%Y"), y=0, label = "Coup attempt", angle=90, hjust=0, size = 5)
#save to png
png("/tmp/kenya_population_density.png", 1600, 800)
p + annotate("text", x = as.Date("1952", "%Y"), y=0, label = "MauMau", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1941", "%Y"), y=0, label = "WW2", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1963", "%Y"), y=0, label = "Independence", angle=90, hjust=0, size = 5) + annotate("text", x = as.Date("1982", "%Y"), y=0, label = "Coup attempt", angle=90, hjust=0, size = 5)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment