Created
December 12, 2013 21:32
-
-
Save andybega/7935847 to your computer and use it in GitHub Desktop.
Quick look at the Global WITS data Gary sent us.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("/Volumes/political-science/shared/ICEWS Project/C-IED/Data/Global_WITS") | |
# Read as txt chunk | |
# The first 16 lines are meta data | |
wits.text <- readLines("WITS.csv") | |
head(wits.text, n=16) | |
# Get actual data | |
wits <- read.csv(text=wits.text, header=TRUE, skip=16) | |
wits$event_start_date <- as.Date(wits$event_start_date, format="%d-%b-%y") | |
wits$event_end_date <- as.Date(wits$event_end_date, format="%d-%b-%y") | |
library(plyr) | |
wits$longitude <- revalue(wits$longitude, c("#N/A"="NA")) | |
wits$latitude <- revalue(wits$latitude, c("#N/A"="NA")) | |
wits$longitude <- as.numeric(as.character(wits$longitude)) | |
wits$latitude <- as.numeric(as.character(wits$latitude)) | |
# Daily count | |
daily <- ddply(wits, .(event_start_date), summarize, count=length(event_start_date)) | |
library(zoo) | |
png(file="~/Desktop/wits-daily.png", width=600, height=400) | |
plot(daily, type="l") | |
lines(daily$event_start_date, rollmean(daily$count, k=30, fill=NA), col="red") | |
dev.off() | |
# Map it | |
library(cshapes) | |
world <- cshp(as.Date("2011-01-01")) | |
points <- wits[complete.cases(wits[, c("latitude", "longitude")]), c("latitude", "longitude")] | |
library(scales) # for alpha() | |
png(file="~/Desktop/wits-map.png", width=1200, heigh=800) | |
plot(world, col="wheat", bg="lightblue1", border="gray70") | |
points(points$longitude, points$latitude, pch=20, col=alpha("red", 0.2)) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment