Skip to content

Instantly share code, notes, and snippets.

Felix Haass felixhaass

Block or report user

Report or block felixhaass

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@felixhaass
felixhaass / Spacewalks.R
Created Apr 22, 2015
Plot annual number of spacewalks by Russia & US
View Spacewalks.R
library(readr)
# read
eva <- read_csv("Extra-vehicular_Activity__EVA__-_US_and_Russia.csv")
# extract years from somewhat inconsisten Date variable
eva$year <- stringi::stri_extract_last_regex(eva$Date, "\\d{4}") # get year
eva$year <- as.numeric(eva$year)
# prepare plot data
@felixhaass
felixhaass / BnH.R
Last active Aug 29, 2015
Population Development of Bosnia and Herzegovina
View BnH.R
library(dplyr)
library(countrycode)
WDI("BA", indicator = c("SP.POP.TOTL"), start = 1975, end = 2011) %>%
select(year, SP.POP.TOTL) %>%
plot(., xlab = "", ylab = "",
main = "Population Development of Bosnia and Herzegovina")
mtext("Source: World Bank", side = 1, line = 3, adj = 1, cex = .6)
@felixhaass
felixhaass / ssmt14nationalities.R
Last active Aug 29, 2015
Breakdown of ECPR SSMT14 Nationalities (Edit: In fact, this rather counts the countries of participants' institution affiliation.)
View ssmt14nationalities.R
library(XML)
library(ggplot2)
# This is a snapshot from the ECPR Moodle's Participant, copy & pasted in HTML
# I've deleted names for privacy reasons
ecpr <- readLines("https://www.dropbox.com/sh/9swobnm3s1lth00/AABHowrIWds1G4pfybDdU0q8a/Participants.htm?dl=1")
# convert to data.frame
ecpr_df <- as.data.frame(readHTMLTable(ecpr, header = FALSE))
@felixhaass
felixhaass / GoT_screentime.R
Last active Aug 29, 2015
This code reproduces the data and plots in this blog post on each Game of Thrones character's screen time on the show in seasons 1 to 3.
View GoT_screentime.R
got <- readLines("GoT_screentime_full.txt", encoding="UTF-8")
gotdf <- data.frame(name=vector(),
minutes=vector(),
seconds=vector(),
seasons=vector(),
episode_count=vector())
for(i in 1:length(got)) {
char <- strsplit(got[i], split=" = |\\. |\\(|\\:|; |)")
@felixhaass
felixhaass / rankAfricanTCCs.R
Created Oct 19, 2013
This code ranks all African states that have contributed troops to UN Peacekeeping Operations by summing their monthly contributions. Note that this does not equal each country's actual troop deployment over time, since the scripts simply sums each monthly contribution which might not actually differ from the country's contribution in the preced…
View rankAfricanTCCs.R
pko <- read.table("./data/Data.Full.csv", header=TRUE, sep=",")
pkoAfricaTotal <- pko[pko$tcc.continent=="Africa", ] # subset all African TCCs
contribSum <- rowsum(pkoAfricaTotal$total,
pkoAfricaTotal$tcc) # sum all contributions
topTCC <- contribSum[order(contribSum[,1], decreasing=TRUE), ] # order countries
# convert to dataframe
@felixhaass
felixhaass / TCCs_Africa.R
Last active Dec 25, 2015
This code maps African states' monthly contributions to UN Peacekeeping operations, using data from http://www.providingforpeacekeeping.org/contributions/. Darker colors mean more contributions. The script generates a .gif of about 5Mb size.
View TCCs_Africa.R
library(rworldmap)
library(classInt)
library(Cairo)
library(RColorBrewer)
# note that the 'animation' package requires ImageMagick to convert .png
# to GIF: http://www.imagemagick.org/script/binary-releases.php
library(animation)
################
@felixhaass
felixhaass / PKOcontributionsToAfrica_bycontinent.R
Last active Dec 25, 2015
This piece of code produces a graphic that depicts trends in contributions to UN peacekeeping on the African continent, by continent. It uses data from http://www.providingforpeacekeeping.org/contributions/
View PKOcontributionsToAfrica_bycontinent.R
# install the following packages
library(scales)
library(ggplot2)
library(reshape)
library(Cairo)
library(RColorBrewer)
################
# Prepare data #
@felixhaass
felixhaass / PKOcontributionsToAfrica.R
Last active Dec 25, 2015
This piece of code produces a graphic that depicts trends in contributions to UN peacekeeping on the African continent, both by all countries worldwide and by African countries only. It uses data from http://www.providingforpeacekeeping.org/contributions/
View PKOcontributionsToAfrica.R
# install the following packages
library(scales)
library(ggplot2)
library(reshape)
library(Cairo)
################
# Prepare data #
################
View drone_data.R
library(ggplot2)
library(Cairo)
library(scales)
library(RCurl)
library(rjson)
#################################
# Data preparation from web API #
#################################
You can’t perform that action at this time.