A line chart with mouseover so that you can read the y-value based on the closest x-value. The x-value is found using d3.mouse and scale.invert. The y-value is then found by bisecting the data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function returns quater scores from Wikipedia Super Bown pages | |
get.scores<-function(numeral) { | |
# Base URL for Wikipedia | |
wp.url<-getURL(paste("http://en.wikipedia.org/wiki/Super_Bowl_",numeral,sep="")) | |
wp.data<-htmlTreeParse(wp.url, useInternalNodes=TRUE) | |
score.html<-getNodeSet(wp.data,"//table[@style='background-color:transparent;']") | |
score.table<-readHTMLTable(score.html[[1]]) | |
score.table<-transform(score.table, SB=numeral) | |
return(score.table) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Forked from @BrianAbelson | |
library('rjson') # For parsing json in R | |
library('RCurl') # For sending an http request | |
library('plyr') # For ddply | |
# Takes an data frame with a unique id column and an address column at the very least | |
# it returns a data frame with the uid, lat, lng and specificity of geocoding | |
# use the uid to join these results back to your data if you want | |
# you can also accomplish roughly the same thing with a for loop instead of ddply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this function takes an input numeric vector and | |
# partitions it into a set number of breaks | |
# it then assigns a color to each break via RColorBrewer | |
assignColors <- function(var, | |
n = 9, # number of colors / breaks | |
style = "jenks", # can be changed to other methods in "classIntervals" | |
pal = "RdYlBu", # Palettes from RColorBrewer | |
na_color ='#787878', # Color to give NA's | |
na_omit = FALSE, # Logical, argument above will be irrelevant if TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE counties_results o SET pres_dem_pct = n.pres_dem_pct, pres_gop_pct = n.pres_gop_pct, | |
pres_oth_pct = n.pres_oth_pct, pres_pctrpt = n.pres_pctrpt | |
FROM ( VALUES | |
(48.51, 39.69, 11.8, 100, 'AK', '02000'), | |
(51.65, 41.67, 6.68, 100 , 'AL' , '01001' ), | |
(52.14, 42.4, 5.46, 100 , 'AL' , '01003' ), | |
(51.94, 42.24, 5.82, 100 , 'AL' , '01005' ), | |
(60.28, 34.95, 4.76, 100 , 'AL' , '01007' ), | |
(53.19, 42.04, 4.77, 100 , 'AL' , '01009' ), | |
(45.07, 50.85, 4.08, 100 , 'AL' , '01011' ), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d <- read.csv("all_posts.csv", stringsAsFactors=F) | |
pattern <- "regex here" | |
d$guns <- 0 | |
d$guns[grep(pattern, d$text)] <- 1 | |
d_guns <- d[d$guns==1,] | |
write.csv(d_guns, "gun_posts.csv", row.names=F) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script src="http://mbostock.github.com/d3/d3.v2.js?2.8.1"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
rect { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script src="http://mbostock.github.com/d3/d3.v2.js?2.8.1"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
rect { |
A quick visual reference to every ColorBrewer scale; colors by Cynthia Brewer. Available in CSS and JS format. Click on a palette to log the constituent colors in hexadecimal RGB to the console.
Fork adds the ColorBrewer name as a label and the Spacegray 80s Dark palette.
Make with make topo/va-counties.json
in the U.S. Atlas project.
OlderNewer