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
library(rvest) | |
library(httr) | |
dem <- html_session("http://www.despair.com/demotivators.html", | |
user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2")) | |
quotes <- data.frame(category=dem %>% html_nodes(xpath="//div/a/h3") %>% html_text(), | |
text=dem %>% html_nodes(xpath="//div[@class='tilecontents']/p") %>% html_text(), | |
image_url=dem %>% html_nodes(xpath="//img[@class='tileimg']") %>% html_attr("src"))[-1,] |
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
library(maptools) | |
library(ggplot2) | |
library(gridExtra) | |
library(scales) | |
# adapted from http://r.789695.n4.nabble.com/maptools-sunrise-sunset-function-td874148.html | |
ephemeris <- function(lat, lon, date, span=1, tz="UTC") { | |
lon.lat <- matrix(c(lon, lat), nrow=1) |
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
library(rgeos) | |
library(rgdal) # needs gdal > 1.11.0 | |
library(ggplot2) | |
# map theme | |
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") | |
# topojson from the bl.ocks example | |
map = readOGR("us.json", "counties") |
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
library(rgeos) | |
library(rgdal) # needs gdal > 1.11.0 | |
library(ggplot2) | |
# map theme | |
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") | |
# use the topojson from the bl.ocks example | |
map = readOGR("us.json", "counties") |
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
library(rgeos) | |
library(rgdal) # needs gdal > 1.11.0 | |
library(ggplot2) | |
# map theme | |
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") | |
# adapted from http://stackoverflow.com/questions/6862742/draw-a-circle-with-ggplot2 | |
# computes a circle from a given diameter. we add "id" so we can have one big | |
# data frame and group them for plotting |
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
library(maps) | |
library(data.table) | |
library(dplyr) | |
library(ggplot2) | |
library(grid) | |
library(RColorBrewer) | |
# takes in a numeric vector and returns a sequence from low to high | |
rangeseq <- function(x, by=1) { | |
rng <- range(x) |
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
library(data.table) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(scales) | |
library(grid) | |
library(statebins) | |
library(gridExtra) | |
# http://www.washingtonpost.com/wp-srv/special/investigative/asset-seizures/data/all.json |
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
#include <Rcpp.h> | |
#include <arpa/inet.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
using namespace Rcpp ; |
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
library(reshape2) | |
library(ggplot2) | |
library(scales) | |
library(RColorBrewer) | |
dat <- read.table(text="Crime Frequently Occassionally Rarely_Never Does_not_apply rank | |
Credit_card_hacked 41 28 29 2 1 | |
Computer_smartphone_hacked 34 28 35 4 2 | |
Home_burglarized_not_present 18 27 55 1 3 | |
Car_stolen_not_present 15 27 56 2 4 |