简体   繁体   English

是否有一种方法可以省略R的plot.zoo函数中的时间间隔?

[英]Is there a method to omit time intervals in plot.zoo function of R?

I have a time series of zoo and POSIXct class using second intervals. 我有一个使用第二个间隔的zoo和POSIXct类的时间序列。 However, as is usually the case in financial time series, there are often long time gaps without information (ex. overnight). 然而,正如金融时间序列中的情况一样,通常存在长时间缺口而没有信息(例如,隔夜)。 When using plot.zoo, the useful (populated) intervals appear scrunched relative to the unused intervals. 使用plot.zoo时,有用(填充)的间隔相对于未使用的间隔显得较小。 Is there some way to simply omit time intervals in the plotting function of plot.zoo(). 是否有一些方法可以简单地省略plot.zoo()的绘图功能中的时间间隔。 PS It's possible to just simply plot the continuous time series (plot(ts(obj)), but then the time information is lost on the x axis. PS可以简单地绘制连续时间序列(plot(ts(obj)),但随后时间信息在x轴上丢失。

@AndresT Thanks for the idea, but the data is already filtered. @AndresT感谢您的想法,但数据已经过滤。 It is the plot.zoo() function that appears to be padding unused sample intervals to keep the total x range active. plot.zoo()函数似乎填充未使用的采样间隔以保持总x范围有效。 Pls see example below. 请参阅下面的示例。

library(zoo)
st<-Sys.time()
t<-c(st, st+500, st+1000, st+1500, st+2000, st+90000, st+95000, st+100000)
rn<-runif(7)
zr<-zoo(rn, order.by=t)
plot.zoo(zr,type='o')

compare to the uniform spacing from plot(ts(data)) 比较绘图的均匀间距(ts(数据))

layout(1:2)
plot.zoo(zr, type='o')
plot(ts(zr),type='o')

So I would like to basically have the 2nd ts plot, but labeled with the corresponding x-axis labels from the 1st plot.zoo() function. 所以我想基本上有第二个ts图,但标有第一个plot.zoo()函数的相应x轴标签。

Try this: 尝试这个:

library(quantmod)
chartSeries(zr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM