plot.xts + abline not quite accurate?

2019-07-25 06:26发布

问题:

I am using xtsExtra to plot some scatter graphs of xts objects and wanted to draw a horizontal line through zero but it looks like its in the wrong place...please see the code below? is this a bug?

set.seed(123)
require(xts)
f <- xts(rnorm(100,0.0001,0.003),Sys.Date()-c(100:1))
f1 <- xts(rnorm(100,0.0001,0.003),Sys.Date()-c(100:1))
require(xtsExtra)
plot(f,f1)
abline(h=0,col='red')

回答1:

Jeff Ryan may have answered this here:

Try,

abline(v=.index(X)[50], col="red")

Note the "dot" in .index. The fact is that xts uses the internal POSIXct(like) time for the x-axis, so you need to access it that way.



标签: r xts