(This article was first published on One Tip Per Day, and kindly contributed to R-bloggers)
Thanks to the Revolutions blog, several things learned here:
1. R code for heat calendar
2. generate SVG from R
3. pretty-R tool
1. R code for heat calendar
2. generate SVG from R
3. pretty-R tool
OK. Let’s explain it by plotting the fund WASCX (IVY ASSET STRATEGY FUND CLASS C) from 2009-03-14:
# source code of calendarHeat (by Paul Bleicher)
source("http://blog.revolution-computing.com/downloads/calendarHeat.R")
# fetch stock time series data from Yahoo finance
stock <- "WASCX"
start.date <- "2009-03-14"
end.date <- Sys.Date()
quote <- paste("http://ichart.finance.yahoo.com/table.csv?s=",
stock,
"&a=", substr(start.date,6,7),
"&b=", substr(start.date, 9, 10),
"&c=", substr(start.date, 1,4),
"&d=", substr(end.date,6,7),
"&e=", substr(end.date, 9, 10),
"&f=", substr(end.date, 1,4),
"&g=d&ignore=.csv", sep="")
stock.data <- read.csv(quote, as.is=TRUE)
# display in SVG format
svg("WASCX.svg",width=14,height=7)
calendarHeat(stock.data$Date, stock.data$Adj.Close,
varname="WASCX Adjusted Close")
dev.off()
To leave a comment for the author, please follow the link and comment on their blog: One Tip Per Day.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...