Skip to content

Instantly share code, notes, and snippets.

@hobbes7878
hobbes7878 / acs-example.R
Created December 13, 2016 15:36
A simple example showing how to fetch census data with the acs package in R
library(dplyr)
# Load acs library
# Complete docs at https://cran.r-project.org/web/packages/acs/acs.pdf
library(acs)
# First, create a geography
# For example, all counties in Texas
tx.counties = geo.make(county="*", state='TX')
# Or all tracts in Dallas and Tarrant county, using fips code
library(RPostgreSQL)
library(dplyr)
library(lazyeval)
library(userfriendlyscience)
# DB Connections
partd <- tbl(src_postgres(dbname = "propublica", user="postgres"), "partd")
# Change specialty filter
@hobbes7878
hobbes7878 / nearest.js
Last active August 29, 2015 14:18
A function to calculate the nearest match based on a shared set of ratings.
function manhattan(userRating, matchRating){
/*
Calculates the manhattan distance between two ratings sets.
ratings are objects like this:
{speed:1, fitness:3, likeability:6}
We assume both sets have the same ratings categories, just different scores.
*/
var distance = 0;
for (rating in userRating){
distance = distance + Math.abs(userRating[rating] - matchRating[rating])
@hobbes7878
hobbes7878 / README.md
Last active February 12, 2021 16:31
#NICAR15: D3 stock chart

An simple multi-line chart that pivots from raw values to percent change using separate CSVs.

@hobbes7878
hobbes7878 / README.md
Last active August 29, 2015 14:16
#NICAR15: D3's General Update Pattern

A intro demonstration of the general update pattern on a simple HTML table.

@hobbes7878
hobbes7878 / README.md
Last active August 29, 2015 14:16
Scatter plot pivot

A scatter plot that pivots one axis from raw to percent.

@hobbes7878
hobbes7878 / README.md
Last active August 29, 2015 13:56
Stadium Chart

Stadium Chart

A solution to proportional comparisons between independent groups, inspired by my memory of stadium checkers.

@hobbes7878
hobbes7878 / d3-viz.js
Last active August 29, 2015 13:56
Groupable Sortable Bar Chart with JSONSelect
//Add items to select
var chems = JSONSelect.match(".chem",rawdata).sort();
//All as first option
chems.splice(chems.indexOf("All"),1)
var opt = document.createElement('option');
opt.value='All';
opt.innerHTML='All';
document.getElementById("drug_drop").options.add(opt)
@hobbes7878
hobbes7878 / data.js
Last active December 29, 2015 02:49
Horizontal Bar Chart
var dataset = {
data1 :
{ chem:"Amitriptyline",
data : [
{"value":.8244,"name":"Least"},
{"value":.7776,"name":"Less"},
{"value":.4922,"name":"More"},
{"value":.4567,"name":"Most"}
]