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 / ivmooc-a02-ggplot.R
Created January 21, 2015 15:40
IV MOOC Assignment 2 (temporal) ggplot code
library(ggplot2)
library(dplyr)
library(gridExtra)
dat <- read.csv("data/burst.csv") # generated by Sci2
dat$idx <- rownames(dat)
dat$size <- dat$Weight / dat$Length
gg <- ggplot(dat, aes(x=Start, xend=End, y=reorder(idx, Start), yend=idx))
@hrbrmstr
hrbrmstr / continents.json
Created January 22, 2015 01:01
Continents GeoJSON
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrbrmstr
hrbrmstr / app.R
Last active February 17, 2020 14:13
Example basic shinydashboard framework
library(shiny)
library(shinydashboard)
library(sparkline)
library(httr)
library(jsonlite)
library(data.table)
library(dplyr)
library(rvest)
library(magrittr)
library(XML)
a <- -.6 #slope
j <- 0
for (a in seq(-3, 3, by=0.1)) {
b <- .3 #intercept
timeserieslength <- 10 #Number of iterations
y1 <- .3 #initial Value
y2 <- 0
t <- 0
for (i in 1:timeserieslength) {
y2[i] <- (a*y1[i])+b
@hrbrmstr
hrbrmstr / gunspercapitaus.R
Created February 3, 2015 16:17
Guns per capital circa 2013 (US states)
library(rvest)
library(dplyr)
library(ggplot2)
url <- "http://www.bloomberg.com/visual-data/best-and-worst//most-registered-guns-per-capita-states"
pg <- html(url)
tab <- pg %>% html_nodes("table")
@hrbrmstr
hrbrmstr / grid.R
Last active April 21, 2020 13:01
how to make a percentage grid in R
library(ggplot2)
library(tidyr)
dat <- as.data.frame(matrix(rep(c(rep("A", 24), rep("B", 8)), 10), nrow=10, byrow=TRUE))
dat$y <- rownames(dat)
dat %>%
gather(x, value, -y) %>%
mutate(x=as.numeric(gsub("V", "", x))) -> dat
@hrbrmstr
hrbrmstr / server.R
Last active August 29, 2015 14:15
shinyheaRstats - see blog post for details http://rud.is/b/2015/02/12/sweethearstats/
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
dat <- data.frame(t=seq(0, 5*pi, by=0.01))
xhrt <- function(t) 16*sin(t)^3
yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
@hrbrmstr
hrbrmstr / deerm3.R
Created February 13, 2015 16:32
m3
library(mosaic)
duration <- 40
plot.new()
soln <- integrateODE(dD~(1.05*(D-600)) * (1-(D/1300)), D=797, tdur=duration)
plotFun(soln$D(t)~t, tlim=range(1, duration), col="red",
xlab="Years out", ylab="Population (thousands)", main="Deer population model",
ylim=c(0, 1500))
@hrbrmstr
hrbrmstr / sgmarkerex.R
Created March 13, 2015 01:36
state unemployment example for blog post
library(dplyr)
library(streamgraph)
library(pbapply)
# Grab some employment data from BLS --------------------------------------
url <- "http://www.bls.gov/lau/ststdsadata.txt"
dat <- readLines(url)
# Small function to grab data for a particular state ----------------------
@hrbrmstr
hrbrmstr / crime.R
Last active August 29, 2015 14:17
Scraped & streamgraphed Crime data
library(dplyr)
library(rvest)
library(streamgraph)
library(htmltools)
# I'm using disastecenter.com since the FBI API is stupid. I should just wrap
# this into a data package at some point
get_crime <- function(state) {