将垂直线添加到时间序列图中

时间:2017-02-23 02:04:06

标签: r plot time-series timeserieschart

我在下面的代码中绘制了两个时间序列。我想在x轴上每隔10个单位添加一条垂直线,基本上将图形划分为5个方格。任何提示都非常感谢。

Code:
## Plot Forecast & Actual
  ts.plot(ts(CompareDf$stuff1),ts(CompareDf$stuff2),col=1:2,xlab="Hour",ylab="Minu    tes",main='testVar')
legend("topleft", legend = c("Actual","Forecast"), col = 1:2, lty = 1)

Data:
dput(CompareDf)
structure(list(stuff1 = c(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 
48, 49, 50, 51, 52, 53, 54, 55), stuff2 = c(8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57)), .Names = c("stuff1", 
"stuff2"), row.names = c(NA, -50L), class = "data.frame")

1 个答案:

答案 0 :(得分:0)

绘制时间序列数据后,使用abline绘制垂直线。

abline(v = seq(10, 50, 10))

enter image description here