barplot for xts objects

落花浮王杯 提交于 2019-12-19 11:18:19

问题


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 compatible with other R graphics.


回答1:


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")


来源:https://stackoverflow.com/questions/9582033/barplot-for-xts-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!