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(geonames) | |
# list of city names (in Afghanistan) | |
cities <- c("Gereshk", "Lashkar Gah", "Marjah", "Nad-e Ali") | |
-5L), class = "data.frame") | |
# conveninence function to look up and format results | |
GNsearchAF <- function(x) { | |
res <- GNsearch(name=x, country="AF") | |
return(res[1, ]) | |
} |
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
# Example of how to add missing countries/territories to cshapes using another source for | |
# the map data/polygon | |
# | |
library(cshapes) | |
library(rgdal) # need this for projection transform (spTransform) | |
# this returns all polygons, with start and end dates for indepdence | |
# we'll have to manually subset for dates below | |
all <- cshp() |
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
# | |
# copy and run this code in R to setup and source `wikipedia-terrorism.R` from this gist | |
# | |
packs <- c("dplyr", "rvest", "httr", "XML", "stringr", "purrr", "xml2", "tibble", "devtools") | |
need <- packs[!packs %in% rownames(installed.packages())] | |
install.packages(need) | |
devtools::source_gist("https://gist.github.com/andybega/0f16b6a0de0185c157e2a280b5e05074", | |
filename = "wikipedia-terrorism.R") |
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("splm") | |
data("usaww") | |
?usaww | |
# Only Alabama has this policy | |
policy_x <- c(1, rep(0, 47)) | |
names(policy_x) <- rownames(usaww) | |
head(policy_x) |
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
plot(c(1, 2), c(1, 1), col = c("blue", "red"), pch= 19, cex=4) | |
lines(c(1, 2), c(1, 1), col = c("blue", "red"), lwd=3) |
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(cshapes) | |
library(sf) | |
states <- cshp(as.Date("2016-01-01"), useGW = TRUE) | |
states <- st_as_sf(states) | |
yemen <- states[states$CNTRY_NAME=="Yemen", ] | |
plot(yemen[, 1]) |
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("tidyverse") | |
arima_qs <- readr::read_csv("/path/to/forecast_rct_a_subset.csv", | |
col_types = cols(user_id = col_integer())) %>% | |
mutate(Forecaster = factor(Forecaster)) | |
# Add # of questions to each Data source label | |
arima_qs <- arima_qs %>% | |
group_by(Data_source) %>% | |
mutate(by_Data_source_n_ifps = length(unique(ifp_id))) %>% |
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("ggplot2") | |
df <- structure(list(date = structure(c(17532, 17897, 18262, 18993, | |
19358, 19723, 20089), class = "Date"), id = c("9991", "9991", | |
"9991", "9992", "9992", "9992", "9992"), cowcode = c(999, 999, | |
999, 999, 999, 999, 999), y = c(1, 1, 1, 2, 2, 2, 2)), row.names = c(NA, | |
-7L), class = "data.frame") | |
ggplot(df, aes(x = date, y = y, group = cowcode)) + geom_line() |
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
# Dot density map | |
# Eventually should be like http://www.radicalcartography.net/index.html?frenchkisses | |
library(maptools) | |
nc_SP <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], | |
proj4string=CRS("+proj=longlat +ellps=clrk66")) | |
## Not run: | |
pls <- slot(nc_SP, "polygons") |
NewerOlder