Hi I have not used quantmod before so I got the
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()") and str(stock.name) on it to see its structure If you require the "^" before the stock.code insert name = sub("\\..*$","",attributes(stock.name)$dimnames[[2]][1]), otherwise name = stock.code eg chartSeries(stock.name, theme = theme.white, name = sub("\\..*$","",attributes(stock.name)$dimnames[[2]][1]), # subset = 'last 12 months', TA = "addVo(); addSMA(); addEnvelope(); addMACD(); addMomentum(); addROC(); addBBands()") addLines(v = which(stock.name[,4] == max(stock.name[,4])), col = "gray") If this is not what you want it will be somewhere in the stock.name and ?chartSeries Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Sent: Thursday, 10 July 2014 14:00 To: r-help@r-project.org Subject: [R] quantmod: How could I change the name in chartSeries 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") ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.