在 R 中向plot.ts() 图中添加垂直线
我想在 plot.ts()
图中添加一条垂直线:
plot.ts(cbind(a, b, c, d, e, f, g, h),main="Time Series")
a<-seq(1:16);
b<-seq(1:16);
c<-seq(1:16);
d<-seq(1:16);
e<-seq(1:16);
f<-seq(1:16);
g<-seq(1:16);
h<-seq(1:16)
我尝试了 abline(v=8.75)
但这并没有将线放在我希望的位置。由于我使用此函数在图形窗口中有两列图形,因此我需要添加两条垂直线,每列图形各一条。有什么想法吗?
I would like to add a vertical line to a plot.ts()
graph:
plot.ts(cbind(a, b, c, d, e, f, g, h),main="Time Series")
a<-seq(1:16);
b<-seq(1:16);
c<-seq(1:16);
d<-seq(1:16);
e<-seq(1:16);
f<-seq(1:16);
g<-seq(1:16);
h<-seq(1:16)
I tried abline(v=8.75)
but this did not put the line where I hoped. Since I have two columns of graphs in the graphics window with this function, I need to add two vertical lines, one for each column of graphs. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个面板函数,该函数将在 ts.plot 创建的每个面板中运行以处理多个系列。它需要复制lines()函数处理参数的方式,并接受abline的参数,然后abline将在局部坐标系中“工作”:
这就像增强晶格函数,只不过它都是在基础图形中完成的。
最好不要在参数列表中设置 vpos。然后您将从外部获得它的句柄,并且不需要重写该函数。 (你的选择。当我尝试将其传递到 ts.plot 的参数列表中时,我收到了来自“图形警察”的警告。):
You need to create a panel function that will operate within each of the panels that ts.plot creates to handle multiple series. It needs to duplicate how the lines() function handles arguments as well as accept an argument for abline that will then "work" in the local coordinate system:
It's like augmenting lattice functions, except it is all done in base graphics.
It might be better to leave off the setting of vpos in the argument list. Then you will have a handle on it from the outside and won't need to rewrite the function. (Your choice. I was getting warnings from the "graphical police" when I tried passing it in the argument list of ts.plot.):