[R] quantmod: How could I change the name in chartSeries

William william.lian.fang at gmail.com
Thu Jul 10 05:59:32 CEST 2014


hi, guys,

I am just a beginner to the excellent R package, quantmod. I quite don't 
know how to change the y-axis name in the chartSeries function. 
Actually, I want to write some sort of the following function, by which 
I could use just one code  sentence  to complete the financial analysis.

The following function is designed to provide some aspects of the 
S&P500. And now I want to change the "stock.name" on the y-axis as 
"S&P500". Is there anyway to realize this?

THX

         William


#################################################################
stock.price <- function(stock.name, stock.code){
   #### Loading......
   library(zoo)
   library(xts)
   library(TTR)
   library(Defaults)
   library(quantmod)
#------------------------------------------------------------------------------------------------------------------------------------------
   ## Theme: white
   theme.white <- chartTheme("white")
   names(theme.white)
   theme.white$bg.col <- "white"
   theme.white$up.col <- "red"
   theme.white$dn.col <- "green"
#------------------------------------------------------------------------------------------------------------------------------------------
   #### main function
   stock.name <- getSymbols(stock.code, from = "2010-01-01",
                                                 to = Sys.Date(), src = 
"yahoo", auto.assign=FALSE)
   chartSeries(stock.name, theme = theme.white,
               # subset = 'last 12 months',
               TA = "addVo(); addSMA(); addEnvelope();
                   addMACD(); addMomentum(); addROC();
                   addBBands()")
   addLines(v = which(stock.name[,4] == max(stock.name[,4])),
            col = "gray")
}
#################################################################
stock.price(S&P500, "^GSPC")



More information about the R-help mailing list