Scatterplot of two xts time series

I have two timing loops xts

. A small sample of them:

ts1
                      [,1]
2009-05-06 00:00:00 38.414
2009-05-06 00:15:00 45.079
2009-05-06 00:30:00 38.878
2009-05-06 00:45:00 49.889
2009-05-06 01:00:00 41.270
2009-05-06 01:15:00 41.050
2009-05-06 01:30:00 38.951
2009-05-06 01:45:00 39.854
2009-05-06 02:00:00 37.803
2009-05-06 02:15:00 42.930

ts2
                       [,1]
2009-05-06 00:00:00 406.887
2009-05-06 00:15:00 413.298
2009-05-06 00:30:00 409.353
2009-05-06 00:45:00 412.312
2009-05-06 01:00:00 409.353
2009-05-06 01:15:00 415.271
2009-05-06 01:30:00 416.257
2009-05-06 01:45:00 416.257
2009-05-06 02:00:00 416.257
2009-05-06 02:15:00 419.216

      

Now I want to create a ts1 vs ts2 scatter plot. According to the documentation CRAN (and I also found an example in stackoverflow in the same way), it should work as follows: plot(ts1, ts2)

. But I am getting an error.

plot(ts1,ts2)
# Error in plot(xycoords$x, xycoords$y, type = type, axes = FALSE, ann = FALSE,  : 
#  object 'xycoords' not found

      

What will go wrong? It works fine with regular ts

signed ~

, but it doesn't work in xts

. I have also tried plot(ts1[, 1], ts2[, 1])

.

+3


source to share


1 answer


The simplest thing is to just name it plot.zoo

, not allow plot

generic to send to plot.xts

.



ts1 <-
structure(c(38.414, 45.079, 38.878, 49.889, 41.27, 41.05, 38.951, 
39.854, 37.803, 42.93), .Dim = c(10L, 1L), index = structure(c(1241586000, 
1241586900, 1241587800, 1241588700, 1241589600, 1241590500, 1241591400, 
1241592300, 1241593200, 1241594100), tzone = "", tclass = c("POSIXct", 
"POSIXt")), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
"POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "")
ts2 <-
structure(c(406.887, 413.298, 409.353, 412.312, 409.353, 415.271, 
416.257, 416.257, 416.257, 419.216), .Dim = c(10L, 1L),
index = structure(c(1241586000, 1241586900, 1241587800, 1241588700,
1241589600, 1241590500, 1241591400, 1241592300, 1241593200, 1241594100),
tzone = "", tclass = c("POSIXct", "POSIXt")), class = c("xts", "zoo"),
.indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", "POSIXt"), 
.indexTZ = "", tzone = "")
plot.zoo(ts1, ts2)

      

0


source







All Articles