Instantly share code, notes, and snippets.

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
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)
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))
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=" = |\\. |\\(|\\:|; |)")
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
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)
################
View PKOcontributionsToAfrica_bycontinent.R
# install the following packages
library(scales)
library(ggplot2)
library(reshape)
library(Cairo)
library(RColorBrewer)
################
# Prepare data #
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 #
#################################