citibike-data
citibike-data copied to clipboard
added libraries. still throws an error.
howdy Abe
- you might wanna include the dependency library commands for people running fresh/from script. are they jsonlite & xts?
- yours was missing a newline, IDK y
- this still throws an error:
wiggins@tantanmen{citibike_analysis}257: date Fri Feb 20 06:25:40 EST 2015 wiggins@tantanmen{citibike_analysis}258: git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean wiggins@tantanmen{citibike_analysis}259: which R /usr/local/bin/R wiggins@tantanmen{citibike_analysis}260: R -f explore.R
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin14.0.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.
Get the departures
library("rjson")
library(jsonlite)
Attaching package: ‘jsonlite’
The following object is masked from ‘package:utils’:
View
library(xts) Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
json_file <- "http://abe.is/full/of/data/departures.json" json_data <- fromJSON(paste(readLines(json_file), collapse="")) Warning message: In readLines(json_file) : incomplete final line found on 'http://abe.is/full/of/data/departures.json' date = names(unlist(json_data)) date = round(as.POSIXlt(as.numeric(date), origin="1970-01-01"), "hours") values = unname(unlist(json_data)) com = data.frame(date, values) com = xts(com[,-1], order.by=com[,1])
Aggregate by day
departures = period.apply(com, endpoints(com, "days"), sum)
Plot
plot(departures)
Get the temperatures
temps = read.csv("http://abe.is/full/of/data/temps.csv", header=TRUE) temps$datetime = round(as.POSIXct(temps$datetime), "hours") com = data.frame(temps$datetime, temps$temp) com = xts(com[,-1], order.by=com[,1])
Aggregate by day
both = period.apply(com, endpoints(com, "days"), mean)
Plot
par(new = TRUE) plot(both, type='l', col="blue", lwd=2, ylim =c(-0, 100),xaxt="n",yaxt="n",xlab="",ylab="") Error in axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) : formal argument "col" matched by multiple actual arguments Calls: plot -> plot.xts -> axis Execution halted wiggins@tantanmen{citibike_analysis}261: