两个xts时间序列的散点图

时间:2015-07-27 14:52:55

标签: r plot xts

我有两个xts时间序列。一小部分样本:

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

现在我想针对ts2创建一个散点图ts1。根据CRAN的文档(我也以相同的方式在stackoverflow中找到了示例),它应该像这样工作:plot(ts1, ts2)。但是我得到了一个错误。

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

出了什么问题?使用ts符号的普通~效果非常好,但这在xts中不起作用。我也试过plot(ts1[, 1], ts2[, 1])

1 个答案:

答案 0 :(得分:0)

最简单的方法是直接致电plot,而不是让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)

{{1}}