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
## Correlations for blog post | |
library(plyr) | |
# from GT | |
# source directories and first few lines of pull-data.R | |
sql <- | |
"SELECT dateoccured AS date, count(*) AS sigacts | |
FROM sigacts |
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
# from here http://blog.55minutes.com/2013/09/postgresql-93-brew-upgrade/ | |
# Create backup of database | |
/usr/local/cellar/postgresql/9.2.4/bin/pg_dump -h localhost -p 5432 -U ab428 -Fc -b -v -f "/usr/local/var/pg_backup/afghanistan.backup" afghanistan | |
# Upgrade PostGIS | |
brew doctor # fix errors | |
brew update | |
brew upgrade postgres | |
brew upgrade gdal --with-postgres |
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) |
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
# Change to your data | |
data <- data.frame(resp=1:5, | |
w11=sample(1:5, 5, replace=TRUE), | |
w12=sample(1:5, 5, replace=TRUE), | |
w13=sample(1:5, 5, replace=TRUE)) | |
data$LoySum <- apply(data[, c("w11", "w12", "w13")], 1, mean) | |
# Names of the variables we want to look at | |
q.names <- c("w11", "w12", "w13") |
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
worldMap <- function(x, id, data, date='2008-01-01', legend.title=NULL, | |
maxy=1) { | |
# Input 2-column matrix with unique identifier and data to be mapped for | |
# state slice in "date", output thematic map. | |
require(cshapes) | |
require(maptools) | |
require(RColorBrewer) # for color palettes | |
require(plyr) | |
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
# Log in to event database first, e.g. | |
# mysql -u xxx -p -h IPaddress -D event_data | |
SET @countryid = (SELECT id FROM countries WHERE countryname='CYPRUS'); | |
# Pull events and related information, takes 1.5m for Cyprus, and save | |
# to a csv file | |
CREATE TABLE temp_results AS | |
SELECT e.event_ID, | |
e.event_date, |
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
# Libraries | |
library(RMySQL) | |
# Connect to server | |
conn <- dbConnect(MySQL(), user="ab428", password="", | |
dbname="event_data", host="") | |
country <- "Turkey" | |
start.date <- "2013-05-15" | |
end.date <- "2013-06-15" |
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
library(ggmap) | |
library(source.gist) | |
# Get data frame with coordinates for points | |
source.gist("6765348") | |
head(turkey.prot) | |
# Get background map | |
tr.map <- get_map(location=c(lon=34, lat=37), zoom=5, maptype="terrain", filename="~/Desktop/ggmapTemp") | |
p <- ggmap(tr.map) + |
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
turkey.prot <- | |
structure(list(source = c("icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", |
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
library(ggmap) | |
library(source.gist) | |
# Get data frame with coordinates for points | |
source.gist("6705264") | |
head(egy.points) | |
# Get background map | |
egy.map <- get_map(location=c(lon=30, lat=26), zoom=6, maptype="terrain", filename="~/Desktop/ggmapTemp") | |
p <- ggmap(egy.map) + |