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