Load the Quandl package with ggplot2 and scales. Set the auth key then dl the dataset:
options(rpubs.upload.method = "internal")
library("Quandl", lib.loc = "C:/Program Files/R/R-3.0.0/library")
library("ggplot2", lib.loc = "C:/Program Files/R/R-3.0.0/library")
library("scales", lib.loc = "C:/Program Files/R/R-3.0.0/library")
## Quandl.auth('//redacted//') ## obtain your own Quandl API key
bitcoin <- Quandl("BITCOIN/B2CUSD")
## Warning: It would appear you aren't using an authentication token. Please
## visit http://www.quandl.com/help/r or your usage may be limited.
Peek at the BTC data frame:
head(bitcoin)
## Date Open High Low Close Volume (BTC) Volume (Currency)
## 1 2011-04-01 1 3 0.2 1 3098 2920
## 2 2011-04-02 1 1 1.0 1 0 0
## 3 2011-04-03 1 1 1.0 1 0 0
## 4 2011-04-04 1 1 1.0 1 0 0
## 5 2011-04-05 1 1 1.0 1 0 0
## 6 2011-04-06 1 1 1.0 1 0 0
## Weighted Price
## 1 0.9424
## 2 1.0000
## 3 1.0000
## 4 1.0000
## 5 1.0000
## 6 1.0000
tail(bitcoin)
## Date Open High Low Close Volume (BTC) Volume (Currency)
## 291 2012-01-16 8 8 8 8.0 0.0 0.0
## 292 2012-01-17 8 8 8 8.0 0.0 0.0
## 293 2012-01-18 8 8 8 8.0 0.0 0.0
## 294 2012-01-19 8 8 8 8.0 0.0 0.0
## 295 2012-01-20 8 8 8 8.0 0.0 0.0
## 296 2012-01-21 8 7 5 6.5 6.6 37.9
## Weighted Price
## 291 8.000
## 292 8.000
## 293 8.000
## 294 8.000
## 295 8.000
## 296 5.742
names(bitcoin)
## [1] "Date" "Open" "High"
## [4] "Low" "Close" "Volume (BTC)"
## [7] "Volume (Currency)" "Weighted Price"
Basic plot of the BTC time series:
ggplot(bitcoin, aes(x = Date, y = Close)) + geom_line() + labs(x = "BitCoin (BTC)")
–> Inspired by The Stubborn Mule Blog , via R-Bloggers.com, and +Roland Koffler