Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.