Skip to content

Instantly share code, notes, and snippets.

View awhstin's full-sized avatar
🦬

Austin Wehrwein awhstin

🦬
View GitHub Profile
library(igraph)
library(plotly)
library(plyr)
library(curl)
G <- read.graph("dolphins.gml", format = c("gml"))
L <- layout_nicely(G)
#marker size
#need plyr loaded
size<-count(es$V2)
size<-rename(size,c("x"="V2"))
es<-join(es,size, by='V2', type="left")
library(ggplot2)
library(ggthemes)
library(plyr)
library(rvest)
ice_cream <- read_html("http://future.aae.wisc.edu/data/annual_values/by_area/2252?tab=sales")
ice_table <- ice_cream %>%
html_nodes('table') %>%
html_table(fill=TRUE)
stats<-data.frame(ice_table[2])
stats$Year<-as.character(stats$Year)
ggplot(stats, aes(x=Year, y=Value)) + theme_tufte(base_size=14, ticks=F) +
geom_bar(width=0.25, fill="gray", stat = "identity") + theme(axis.title=element_blank()) +
geom_hline(yintercept=seq(5, 20, 5), col="white", lwd=1) +
annotate("text", x = 20, y = 18, adj=1, family="serif",
label = c("Per Capita\n U.S. Frozen Dairy\n Product Consumption\n (Annual)"))
library(ggplot2)
library(directlabels)
#plot
ggplot(summary, aes(x=Year, y=mean, col=Region))+geom_line(alpha=.45,size=.75)+ theme_tufte( ticks=F)+
geom_vline(xintercept=advances$Year, col="light gray",alpha=.35 ,lwd=1 )+
theme(legend.position="none")+
ylab("Mean Life Expectancy")+
geom_dl(aes(label = Region), method = list(dl.combine( "last.points"), cex = 0.6))+
geom_text(aes(x=1799, label="Vaccines", y=20 ), colour="gray", angle=270)+
geom_text(aes(x=1849, label="Surgical Anesthetic", y=21), colour="gray", angle=270) +
@awhstin
awhstin / DH1.R
Last active December 1, 2016 14:13
library(dplyr)
library(ggplot2)
library(viridis)
library(ggthemes)
#import all the files
temp <- list.files(pattern="*.csv")
alldata <- do.call(rbind, lapply(temp, function(x) read.csv(x, stringsAsFactors = FALSE)))
alldata$day <- strptime(alldata$starttime, format = "%m/%d/%Y")
alldata$day <- as.character(alldata$day)
@awhstin
awhstin / DH2.R
Created September 18, 2016 01:14
rides.raw<-aggregate(alldata$trip_id ,by=list(alldata$day),length)
@awhstin
awhstin / DH3.R
Created September 18, 2016 01:19
rides.raw$Group.1<-as.Date(rides.raw$Group.1,format='%m/%d/%Y')
rides.raw$days<-factor(weekdays(rides.raw$Group.1,T),levels = rev(c("Mon", "Tue", "Wed", "Thu","Fri", "Sat", "Sun")))
rides.raw$week<-as.numeric(format(rides.raw$Group.1,"%W"))
rides.raw$month<-as.numeric(format(rides.raw$Group.1,"%m"))
rides.raw$year<-as.numeric(format(rides.raw$Group.1,"%Y"))
@awhstin
awhstin / DH4.R
Created September 18, 2016 01:25
ggplot(rides.raw, aes(x = week, y = days, fill = x)) +
scale_fill_viridis(name="Divvy Rides",option = "C", limits = c(0, max(rides.raw$x))) +
geom_tile(color = "white", size = 0.4)+facet_wrap("year", ncol = 1) +
scale_x_continuous(expand = c(0, 0), breaks = seq(1, 52, length = 12),
labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))+
theme_tufte()