barplot for xts objects

后端 未结 1 1247
醉话见心
醉话见心 2021-01-16 14:20

Can I use barplot to plot xts objects? Or is there any similar function that I can use? quantmod is not what I\'m talking about since it\'s not flexible enough and not compa

相关标签:
1条回答
  • 2021-01-16 15:03

    You can extract the indices and the values of an xts or zoo object with index and coredata: this should suffice to plot it the way you want.

    # Sample data
    library(quantmod)
    getSymbols("^GSPC")
    x <- Vo( GSPC )
    
    # Base graphics
    plot( index(x), coredata(x), type="h" )
    
    # ggplot2
    d <- data.frame( time=index(x), volume=drop(coredata(x)) )
    library(ggplot2)
    ggplot(d, aes(time, volume)) + geom_bar(stat="identity")
    
    0 讨论(0)
提交回复
热议问题