This file contains hidden or 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(rjson) | |
| library(RCurl) | |
| client_id <- "client id here" | |
| client_secret <- "client secret here" | |
| redirect_uri <- "https://localhost/oauth2callback" | |
| auth_url <- "https://accounts.google.com/o/oauth2/auth" | |
| scope <- "https://www.googleapis.com/auth/prediction" | |
| api_key <- "api key here" |
This file contains hidden or 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
| { | |
| "kind": "prediction#output", | |
| "id": "sample.languageid", | |
| "selfLink": "https:\/\/www.googleapis.com\/prediction\/v1.5\/hostedmodels\/sample.languageid\/predict", | |
| "outputLabel": "Spanish", | |
| "outputMulti": [ | |
| { | |
| "label": "English", | |
| "score": 0.051492 | |
| }, |
This file contains hidden or 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
| # 4ijn-s7e5 is food inspections in Chicago data set 2010 to present | |
| # may take a minute or two... | |
| df <- read.csv("http://data.cityofchicago.org/views/4ijn-s7e5/rows.csv", | |
| stringsAsFactors = F) | |
| names(df) <- tolower(names(df)) | |
| # we don't want missing values in lat or lon | |
| df <- subset(df, !is.na(longitude) & !is.na(latitude)) | |
| # let's look at complaints / food poisonings... |
This file contains hidden or 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(httr) | |
| google <- oauth_endpoint(NULL, "auth", "token", base_url = auth_url) | |
| myapp <- oauth_app("google", client_id, secret=client_secret) | |
| # this will open a browser window and ask permission for access | |
| cred <- oauth2.0_token(google, myapp, scope = scope) |
This file contains hidden or 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(RCurl) | |
| library(RJSONIO) | |
| library(ggmap) | |
| df <- read.csv("submissions-2013-11-05.csv", stringsAsFactors=F) | |
| names(df) <- tolower(names(df)) | |
| # order by id, or basically date | |
| df <- df[order(df$id),] | |
| df$lat <- df$lng <- rep(NA, nrow(df)) |
This file contains hidden or 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(ggplot2) | |
| library(OpenStreetMap) | |
| merc <- projectMercator(df2$lat, df2$lng) #OSM uses mercator | |
| # give openmap the upper right and lower left corners you want for your map | |
| mp <- openmap(c(42.05, -87.96), c(41.62, -87.5), type="osm", minNumTiles=16) | |
| p <- autoplot(mp) + geom_point(aes(x=merc[,1], y=merc[,2]), alpha=.7, size=10) + | |
| theme(line = element_blank(), | |
| text = element_blank(), | |
| line = element_blank(), |
This file contains hidden or 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
| p2 <- qmap("chicago", darken=.1) + geom_point(data=df2, aes(x=lng, y=lat)) + | |
| coord_cartesian(xlim=c(-87.96, -87.5), ylim=c(41.62, 42.05)) | |
| ggsave(plot=p2, "foodborne_p2.png", height=5, width=5) |
This file contains hidden or 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
| shapefile <- readOGR("chicago_city_shapefiles", "City_Boundary") | |
| shapefile.converted <- spTransform(shapefile, CRS("+proj=longlat +datum=WGS84")) | |
| p3 <- p2 + geom_polygon(aes(x = long, y = lat, group=group), alpha=.2, fill="black", | |
| data = shapefile.converted) + | |
| coord_cartesian(xlim=c(-87.96, -87.5), ylim=c(41.62, 42.05)) | |
| ggsave(plot=p3, "foodborne_p3.png", height=5, width=5) |
This file contains hidden or 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(httr) | |
| # 1. Find OAuth settings for yahoo: | |
| # Endpoints described here... | |
| # http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html | |
| yahoo <- oauth_endpoint("get_request_token", "request_auth", "get_token", | |
| base_url = "https://api.login.yahoo.com/oauth/v2/") | |
| # 2. Register an application at... | |
| # https://developer.apps.yahoo.com/dashboard/createKey.html |
This file contains hidden or 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(httr) | |
| # saved my yahoo keys to a file, now, read them in... | |
| creds <- read.table("~/cn/personal/keys/yahoo.txt", stringsAsFactors=F) | |
| consumer.key <- creds[1,1] | |
| consumer.secret <- creds[2,1] | |
| token.url <- "https://api.login.yahoo.com/oauth/v2/" | |
| yahoo <- oauth_endpoint("get_request_token", "request_auth", "get_token", | |
| base_url = token.url) |