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.
Asked
Active
Viewed 2,071 times
1
-
any solution in base R plot? – jangorecki Oct 30 '13 at 20:56
1 Answers
3
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")

Vincent Zoonekynd
- 31,893
- 5
- 69
- 78
-
thank u so much! that inspires me and just by changing this a little bit serves the purpose in my context~~ – billlee1231 Mar 07 '12 at 01:41
-
i am getting this error.. could not find function "barplot.xts" .. am I missing some package? It was working till date. – Arun Raja Aug 17 '16 at 03:30