R - How can I change date format when I plot an xts & zoo object?

前端 未结 1 579
南方客
南方客 2021-01-20 07:05

I am wondering how I can change date format.

The code I am working on is following:

library(quantmod)
getSymbols(\"AAPL\")
price_AAPL <- AAPL[,6]
         


        
相关标签:
1条回答
  • 2021-01-20 07:27

    With xts, you can use major.format directly.

    plot(price_AAPL, main = "The price of AAPL",major.format="%b-%d-%Y")
    

    However, you should know that zoo plots are generally more flexible.

    plot.zoo(price_AAPL, main = "The price of AAPL", xaxt="n", xlab="")
    axis.Date(1,at=pretty(index(price_AAPL)),
                labels=format(pretty(index(price_AAPL)),format="%b-%d-%Y"),
                las=2, cex.axis=0.7)
    

    0 讨论(0)
提交回复
热议问题