Skip to content

Instantly share code, notes, and snippets.

@chelsimoy
chelsimoy / scraping
Last active December 26, 2015 12:08
scraping websites ... just to get to the point where you can begin plotting and sorting...
get_country_data <- function(country_name) {
# this puts a plus instead of the space, which is how the URL behaves
country_name <- gsub(" ", "+", country_name)
#this fixes ivory coast
country_name <- gsub("`", "%60", country_name)
# first part of the url
first_part <- "http://adoption.state.gov/maps/statistics/map_files/statistics.php?special=NONE&year=ALL&country="
@chelsimoy
chelsimoy / Choropleth Map
Last active December 26, 2015 04:49
Creating bar chart (for sorting purposes) and, finally, a choropleth map
data <- read.csv("county-data.csv")
#adds a county column by splitting in front of the parenthesis
data$county <- sapply(strsplit(as.character(data$ACCOMACK.VA.), split="\\("), function(x) { x[1] })
#adds a state column by splitting after the parenthesis
data$state <- sapply(strsplit(as.character(data$ACCOMACK.VA.), split="\\("), function(x) { x[2] })
#resplit the state data to get rid of the parenthesis sign at the end
data$state <- sapply(strsplit(as.character(data$state), split="\\)"), function(x) { x[1] })
@chelsimoy
chelsimoy / Unemployment rates
Last active December 25, 2015 11:29
Using R to chart the comparison between North Dakota's unemployment rate and the national average between 2000 and 2013... this orders, subsets, changes arrays to values (gets rid of the comma in the dataset) and plots lines.
setwd("~/dataviz-fall-2013/breaking-exercise")
data <- read.csv("ssamatab2.csv")
// Creates and orders unemployment rates for 2013 -- Discovers highest and lowest locations are AZ and ND//
Year2013 <- subset(data, Year == "2013")
Year2013 <- Year2013[order(Year2013$Unemployment.Rate, decreasing=T),]
//Want to chart unemployment rates for only North Dakota between 2000 and 2013. This targets North Dakota specifically and puts it in order by year //
ND <- subset(data, Area == "Bismarck, ND MSA")
ND <- ND[order(ND$Year, decreasing=T),]
@chelsimoy
chelsimoy / gist:6575759
Created September 16, 2013 01:20
For help labeling certain networks and their prices
var networks = ["Comedy Central","TNT", "C-SPAN", "The Weather Channel", "MSNBC", "Bravo", "TBS", "ESPN2"]
var labels = svg.selectAll(".g-labels")
.data(prices)
.enter().append("text")
.attr("x", function(d,i) { return 4*i})
.attr("y", function(d) { return height - y(d.X2013) - 14 })
.text(function(d) { return d.Network + " ($"+ d.X2013 +")"; })
@chelsimoy
chelsimoy / highlight-bars.js
Created September 16, 2013 01:00
one way to highlight minor bars
var networks = ["Comedy Central","TNT", "C-SPAN"];
//inside the bars data join, this code is helpful
.classed("g-minor-highlight", function(d) { return networks.indexOf(d.Network) >= 0; });