Skip to content

Instantly share code, notes, and snippets.

View sebastianbarfort's full-sized avatar

Sebastian Barfort sebastianbarfort

View GitHub Profile
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" >
<link rel='stylesheet' href="http://twitter.github.io/bootstrap/assets/js/google-code-prettify/prettify.css">
<link rel='stylesheet' href="http://aozora.github.io/bootplus/assets/css/docs.css">
<link rel='stylesheet' href='http://nvd3.org/src/nv.d3.css'>
# Latex files
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
@sebastianbarfort
sebastianbarfort / KV2013
Last active June 10, 2024 11:57
Download kommunalvalgsdata fra kmdvalg.dk.
library(XML)
# main page
url <- "http://kmdvalg.dk/main"
# read links
url.data <- readLines(url)
doc <- htmlTreeParse(url.data, useInternalNodes = TRUE)
#grab urls
urls <- unlist(xpathApply(doc, "//div[@class='LetterGroup']//a[@href]",
@sebastianbarfort
sebastianbarfort / ggvisQ.R
Last active August 29, 2015 14:07
can you do this in ggvis?
library(ggplot2)
hec <- as.data.frame(xtabs(Freq ~ Hair + Eye, HairEyeColor))
hec$ind = ifelse(hec$Hair == "Blond", 1, 0)
ggplot(hec[1:4, ], aes(x = Hair, y = Freq, fill = factor(ind))) +
geom_bar(stat = "identity",
position = "dodge")
We can't make this file beautiful and searchable because it's too large.
"","data","party","mean"
"1",18.0571583107283,"DF",21.2
"2",22.6252804071813,"DF",21.2
"3",21.1473723979213,"DF",21.2
"4",21.7656534928624,"DF",21.2
"5",23.9863066666691,"DF",21.2
"6",23.7008455200688,"DF",21.2
"7",21.208448335125,"DF",21.2
"8",21.2263754586171,"DF",21.2
"9",24.5294715105661,"DF",21.2
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css'>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script>
<script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js' type='text/javascript'></script>
<script src='//nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script>
@sebastianbarfort
sebastianbarfort / ajps.R
Created November 28, 2015 12:12
AJPS scrape
rm(list = ls())
library("rvest")
library("stringr")
# define functions -----------------------
grab_data = function(url){
require("rvest")
require("stringr")
url = paste(url, "?seq=1#references_tab_contents", sep = "")
link = url %>% read_html