I found rpubs 3 days ago. This is my first try to use rmarkdown and the first time to publish something to rpubs. Just a try. Give me some encouragement. :)
Download Shanghai Stock Index data from yahoo with quantmod package, and compute its daily return.
require("quantmod")
sh <- getSymbols("000001.ss", from = "2012-01-01", auto.assign = FALSE)
rsh <- dailyReturn(sh)
drsh <- data.frame(date = time(rsh), rtn = coredata(rsh))
names(drsh)[2] <- "rtn"
Draw the line chart of daily returns on Shanghai stock index with ggplot2 package.
require("ggplot2")
require("scales")
p <- ggplot(data = drsh, aes(x = date, y = rtn))
p + geom_line() + scale_x_date(breaks = "2 months", labels = date_format("%Y-%m")) +
xlab("month") + ylab("daily return")
Don't forget to load scales package when formatting date formats.
Write to myself:
Well begun is half done.
Thank you visiting my website