Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
@hrbrmstr
hrbrmstr / foralex.R
Created December 24, 2014 17:54
foralex
library(rgdal)
library(rgeos)
library(maptools)
library(mapproj)
us <- readOGR("http://bl.ocks.org/mbostock/raw/4090846/us.json", "states")
proj4string(us) <- CRS("+proj=merc")
map <- fortify(us)
@hrbrmstr
hrbrmstr / phantomjs.R
Created December 29, 2014 15:29
Scraping gnarly sites with phantomjs & rvest
library(rvest)
# example of using phantomjs for scraping sites that use a twisty maze
# of javascript to render HTML tables or other tags
# grab phantomjs binaries from here: http://phantomjs.org/
# and stick it somehere PATH will find it
# this example scrapes the user table from:
@hrbrmstr
hrbrmstr / heatmapcolors.R
Created December 31, 2014 13:43
using tidyr expand to get all the levels, fill NA with 0 and make a heatmap with colors (and text that changes too)
library(dplyr)
library(scales)
library(ggplot2)
library(RColorBrewer)
dat_sum <- dat %>%
mutate(A=factor(A),
B=factor(B)) %>%
group_by(B, A, Outcome) %>%
summarise(outcome_total=n()) %>%
@hrbrmstr
hrbrmstr / latlon2country.R
Last active August 29, 2015 14:12
lat/lon coordinates to country name (or any adm level given proper shapefile)
library(rgdal)
library(magrittr)
# save this locally for realz
world <- readOGR("https://raw.githubusercontent.com/AshKyd/geojson-regions/master/data/source/ne_50m_admin_0_countries.geo.json", "OGRGeoJSON")
# assumes 'places' is a data.frame with at least lat/lon columns
places %>%
Gender Grade Age Race Urban/Rural School Goals Grades Sports Looks Money
boy 5 11 White Rural Elm Sports 1 2 4 3
boy 5 10 White Rural Elm Popular 2 1 4 3
girl 5 11 White Rural Elm Popular 4 3 1 2
girl 5 11 White Rural Elm Popular 2 3 4 1
girl 5 10 White Rural Elm Popular 4 2 1 3
girl 5 11 White Rural Elm Popular 4 2 1 3
girl 5 10 White Rural Elm Popular 3 4 1 2
girl 5 10 White Rural Elm Grades 3 4 2 1
girl 5 10 White Rural Elm Sports 3 2 1 4
@hrbrmstr
hrbrmstr / city-state-geo.R
Last active August 29, 2015 14:13
US City & State to lon/lat without using an API
library(rgeos)
library(rgdal)
library(httr)
library(dplyr)
geo_init <- function() {
try({
GET("http://www.mapcruzin.com/fcc-wireless-shapefiles/cities-towns.zip",
write_disk("cities.zip"))
Data sources:
CDC data on vaccine coverage: http://www.cdc.gov/flu/professionals/vaccination/reporti1112/reporti/index.htm
CDC data on current influenza situation: http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html
Historical flu data: http://www.cdc.gov/flu/weekly/pastreports.htm
Locations of hospitals in Boston: https://data.cityofboston.gov/Public-Health/Hospital-Locations/46f7-2snz
NetLogo, a simple agent based model: http://ccl.northwestern.edu/netlogo/
Nemsis, emergency medical services API (haven't used this one myself): http://www.nemsis.org/v3/downloads/v3Archive.html
Written for R, but useful for epi basics in any language: cran.r-project.org/doc/contrib/Epicalc_Book.pdf
"Provides access to health statistics and information on hospital inpatient and emergency department utilization": http://hcupnet.ahrq.gov/
Healthcare Research and Quality data directory: http://www.ahrq.gov/data/dataresources.htm
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrbrmstr
hrbrmstr / tempanomaly.R
Created January 18, 2015 14:25
NASA GISS’s Annual Global Temperature Anomaly Trends
library(httr)
library(magrittr)
library(dplyr)
library(ggplot2)
# data retrieval ----------------------------------------------------------
pg <- GET("http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.txt",
user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"))
@hrbrmstr
hrbrmstr / world_0_360.json
Created January 18, 2015 16:15
Pacific-centered world map (GeoJSON)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.