Skip to content

Instantly share code, notes, and snippets.

View awhstin's full-sized avatar
🦬

Austin Wehrwein awhstin

🦬
View GitHub Profile
map+geom_segment(data=theages, aes(x=longitude, y=latitude, xend=lon1, yend=lat1, colour=range), alpha=.0025)+
scale_x_continuous(limits = c(-87.8, -87.55))+
scale_y_continuous(limits = c(41.8, 42))+
scale_colour_brewer(palette="Dark2")+
guides(colour = guide_legend(title="Age Range",override.aes = list(alpha = 1)))+
theme(legend.position="none")
#Below you will see the Quarters section is commented out except for the first Quarter,
#I wanted to provide all the data but I only use Q1 in my viz.
library(plyr)
library(ggplot2)
library(ggalt)
library(rgdal)
library(rgeos)
library(maptools)
library(waffle)
map<-ggplot(data=na.df)+geom_polygon(aes(long,lat,group=group),alpha=.5,color="gray")+
theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank(), panel.background = element_rect(fill="white"), axis.ticks=element_blank(), axis.text=element_blank(), axis.title= element_blank())+
scale_x_continuous(limits = c(-87.8, -87.55))+ scale_y_continuous(limits = c(41.8, 42))
map<-ggplot(data=na.df)+geom_polygon(aes(long,lat, group=group),color="black", alpha=.25)+
scale_x_continuous(limits = c(-87.725, -87.575))+ scale_y_continuous(limits = c(41.825, 41.95))
map<-map+geom_segment(data = theages,aes(x=longitude, y=latitude, xend=lon1, yend=lat1, colour=range), alpha=.25)+
scale_colour_brewer(palette="Blues")+
guides(colour = guide_legend(title="Age Range",override.aes = list(alpha = 1)))+
theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank(), panel.background = element_rect(fill="#2FCAFC"), axis.ticks=element_blank(), axis.text=element_blank(), axis.title= element_blank(), legend.position="none")
map+geom_point(data=stationsa,aes(x=longitude, y=latitude), color="white" ,alpha=.55, size=I(5))
plot(shape,lwd=.3, main="Spain")
points(spain$Lon3,spain$Lat3,cex=.01, pch=19, col="red4")
plot(shape,lwd=.3, main="France")
points(france$Lon3,france$Lat3,cex=.01, pch=19, col="royalblue4")
plot(shape,lwd=.3, main="Nederland") points(nether$Lon3,nether$Lat3,cex=.01, pch=19, col="sienna1")
plot(shape,lwd=.3, main="United Kingdom") points(uk$Lon3,uk$Lat3,cex=.01, pch=19, col="gray78")
spain<-fm[fm$Nation=="Spain",]
france<-fm[fm$Nation=="France",]
nether<-fm[fm$Nation=="Nederland",]
uk<-fm[fm$Nation=="United Kingdom",]
plot(shape,lwd=.3, main="Spain") points(spain$Lon3,spain$Lat3,cex=.05, pch=19, col="red4")
@awhstin
awhstin / QuickRScraping.R
Created March 23, 2016 18:32
Loop for web scraping from 2 column dataframe.
library(syuzhet)
library(rvest)
library(plyr)
news<- read.csv("H:/news.csv", stringsAsFactors=FALSE)
newslist<-NULL
for(i in 1:nrow(news)){
article<-read_html(news[i,1])%>%
xml_nodes(news[i,2]) %>%
html_text()
#This code is an addendum to the fantastic code Hadley (rvest/demo/tripadvisor.R) put out on Trip Advisor scraping. It is a for-loop specifically for Attraction
#related entities on Trip Advisor, and runs off a CSV of urls for your attraction.
library(rvest)
testurl <- read.csv("url.csv", header=FALSE, quote="'", stringsAsFactors = F)
list<-unlist(testurl)
tripadvisor <- NULL
library(plotly)
p<-plot_ly(Words, x =outlet, y =Mean,text = rownames(Words), type="bar", showlegend = FALSE, marker=list(color="rgb(55, 83, 109)")) %>%
add_trace(Words,x=Words$outlet, y = Words$X4.13.am,mode="markers" ,name = "Hillary for President",
showlegend = TRUE, marker=list(color="rgb(234, 153, 153)"))%>%
add_trace(Words,x=Words$outlet, y = Words$X26.Apr, mode="markers", name = "Baltimore Riots/Nepal Earthquake",
showlegend = TRUE, marker=list(color="rgb(106, 168, 79)"))%>%
layout(legend = list(x = 0.5, y = 0.90), title = "Mean Sentiment of News Outlets in April 2015")
plotly_POST(p, filename = "News_Sentiment")