R-项目:绘制 2 个有一些日期不匹配的动物园对象(价格系列)
我有 2 个动物园对象 -
10-YR-US-Treasury 和 2-YR-US-Treasury 之间的利率利差(对象名称 = sprd)
S&P 500 指数(对象名称=间谍)
> str(spy)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: num [1:8791] 99.8 100.2 100.1 99.2 98.6 ...
Index: Class 'Date' num [1:8791] 2343 2344 2345 2346 2349 ...
> str(sprd)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: num [1:9088] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...
Index: Class 'Date' num [1:9088] 2343 2344 2345 2346 2349 ...
由于对象中存在 NA 数据点'sprd' 我创建了另一个省略“NA”的对象。该对象的名称是“sprdtmp”。
> str(sprdtmp)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: atomic [1:8704] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...
- attr(*, "na.action")=Class 'omit' int [1:384] 25 70 95 111 118 128 149 190 224 260 ...
Index: Class 'Date' num [1:8704] 2343 2344 2345 2346 2349 ...
我想将两个时间序列绘制在同一个图上,其中 x 轴上的时间/日期和每季度的轴标签。一个问题是 sprdtmp 和间谍对象的数据点数量与股票市场休市而利率市场开放时的数据点数量不同。大多数情况下,日期是重叠的。如果我尝试将两者绘制在同一个图上,这会重要吗?我将如何在一个图中绘制这些对象。
该图的第二部分要求两者具有不同的比例。我想我可以记录标准普尔指数并将其与利差一起绘制出来。但如果我能在一个图中用 2 个不同的尺度绘制 2 个系列,那么对于将来的参考将是很好的。
我昨天和今天早上花了一整夜尝试各种选择,但我似乎无法让它发挥作用。我将非常感谢你的帮助。
I have 2 zoo objects -
Interest rate spread between 10-YR-US-Treasury and 2-YR-US-Treasury (object name = sprd)
S&P 500 index (object name = spy)
> str(spy)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: num [1:8791] 99.8 100.2 100.1 99.2 98.6 ...
Index: Class 'Date' num [1:8791] 2343 2344 2345 2346 2349 ...
> str(sprd)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: num [1:9088] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...
Index: Class 'Date' num [1:9088] 2343 2344 2345 2346 2349 ...
Since there are NA data points in object 'sprd' I created another object that omits "NA". The name of that object is 'sprdtmp'.
> str(sprdtmp)
‘zoo’ series from 1976-06-01 to 2011-03-31
Data: atomic [1:8704] 0.68 0.71 0.7 0.77 0.79 0.79 0.82 0.86 0.83 0.83 ...
- attr(*, "na.action")=Class 'omit' int [1:384] 25 70 95 111 118 128 149 190 224 260 ...
Index: Class 'Date' num [1:8704] 2343 2344 2345 2346 2349 ...
I want to plot both time series on the same plot with time/date on the x-axis and the axis label quarterly. One problem is the sprdtmp and spy objects do not have the same number of data points as there are times when the equity markets are closed while the interest rate markets are open. For the most part the dates overlap. Would this matter if I try to plot both on the same plot? And how would I go about plotting these objects in one plot.
The second part of the plot requires that both are on different scales. I guess I could take a log of the s&p and plot that along with the rate spread. But it would be nice for future reference how I could plot 2 series in one plot with 2 difference scales.
I spent all night yesterday and this morning trying various options but I cant seem to get it to work. I would greatly appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的方法就成功了:
The following did the trick: