Skip to content

Instantly share code, notes, and snippets.

@geojackass
Created July 29, 2015 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geojackass/bf203d3b9f5ccbcfc1b1 to your computer and use it in GitHub Desktop.
Save geojackass/bf203d3b9f5ccbcfc1b1 to your computer and use it in GitHub Desktop.
timeseries data
data <- read.csv('stock_px.csv')
#setup libraries
options(CRAN="http://cran.ism.ac.jp/")
options(repos="http://cran.ism.ac.jp/")
install.packages('ggplot2')
install.package('reshape2')
library(ggplot2)
library(reshape2)
#head(data)
colnames(data)[1] <- "dtm"
data.bind <- cbind(1:nrow(data), data)
head(data.bind)
colnames(data.bind)[1] <- "id"
data.melted <- melt(data.bind, id.var=c('id', 'dtm'))
head(data.melted)
g <- ggplot(data.melted, aes(x=as.Date(data.melted$dtm), y=data.melted$value, colour=data.melted$variable))
g <- g + geom_line(size=1)
g <- g + xlab("Date") + ylab("stock") + ggtitle("stock-prices") + labs(colour="company")
plot(g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment