Skip to content

Instantly share code, notes, and snippets.

View blmoore's full-sized avatar
🙆‍♂️

Benjamin L. Moore blmoore

🙆‍♂️
View GitHub Profile
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://dimplejs.org/dist/dimple.v1.1.1.min.js' type='text/javascript'></script>
<style>
.rChart {
@blmoore
blmoore / index.html
Last active July 2, 2020 03:52
What are the most overrated films?
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://dimplejs.org/dist/dimple.v1.1.1.min.js' type='text/javascript'></script>
<style>
.rChart {
library("RCurl")
library("jsonlite")
library("ggplot2")
library("RColorBrewer")
library("scales")
library("gridExtra")
api.key <- "yourAPIkey"
rt <- getURI(paste0("http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/top_rentals.json?apikey=", api.key, "&limit=50"))
@blmoore
blmoore / plos_authInflation.R
Last active June 28, 2018 15:00
For blog post
options(PlosApiKey = "<insert your API key here!>")
#install_github("rplos", "ropensci")
library("rplos")
library("ggplot2")
require("dplyr")
# Convert author strings to counts
countAuths <- function(cell)
length(unlist(strsplit(cell, ";")))
library("ggplot2")
library("scales")
## Data: http://www.theguardian.com/news/datablog/2009/oct/21/icm-poll-data-labour-conservatives#data (State of the parties spreadsheet)
# ICM poll resultsof ~1000 people taken every month or so
# (more often before an election) as well as election
# results dating from June 1984.
sop <- read.csv("StateOfTheParties.csv", stringsAsFactors=F)
## Data cleanup
@blmoore
blmoore / PRNGanalysis.R
Last active August 29, 2015 13:57
For blog post
library("jsonlite")
library("stringr")
oauth <- scan("yourOAuth.token", "character")
getCMD <- function(user){
# crude system command for querying Github API
newcmd <- paste0("curl -H 'Accept: application/vnd.github.v3.text-match+json Authorization: token ",
oauth, "' 'https://api.github.com/search/code?q=set.seed+in:file+language:R+user:",
user,"&page=1&per_page=500' | grep 'fragment' -")
@blmoore
blmoore / USemploymentPlot.R
Last active August 29, 2015 13:56
for blogpost
require("zoo")
require("ggplot2")
# unemployment
u <- read.csv("Employment.csv", header=T)
u <- melt(u, "Year")
unemployment <- data.frame(date=as.yearmon(do.call(paste, u[,1:2]), "%Y %b"),
rate=u$value)
unemployment <- unemployment[unemployment$date > as.yearmon("2008-12"),]
require(ggplot2)
lm_eqn <- function(m) {
# fromm: http://stackoverflow.com/a/13451587/1274516
l <- list(a = format(coef(m)[1], digits = 2),
b = format(abs(coef(m)[2]), digits = 2),
r2 = format(summary(m)$r.squared, digits = 3));
if (coef(m)[2] >= 0) {
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,l)
} else {
library(plyr)
library(ggplot2)
s <- read.csv("<filename.csv>", sep=",", row.names=NULL)
colnames(s) <- c("date", "type", "desc", "value", "balance", "acc")
s$date <- as.Date(s$date, format="%d/%m/%Y")
s <- s[,1:5]
s$month <- as.Date(cut(s$date, breaks="month"))
s <- subset(s, s$value < 0)