Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在时间序列图上画一条线_R_Plot_Time Series_Line - Fatal编程技术网

R 在时间序列图上画一条线

R 在时间序列图上画一条线,r,plot,time-series,line,R,Plot,Time Series,Line,我有下一个时间序列对象,我使用plot来绘制它: ts <- ts(c(1:4,2:5,3:6,4:7,5:8,6:9,7:10), frequency = 4) plot(ts) 有没有人遇到过同样的问题并设法解决了 我不确定我是否完全理解你想要实现的目标。但以下内容可能会有所帮助 您可以使用以下简单代码行: 这就产生了下面的简单图 完全正确,我将修复这些错误。谢谢 abline(a = 1, b = (ts[length(ts)]- ts[1]) / (length(ts)-1))

我有下一个时间序列对象,我使用plot来绘制它:

ts <- ts(c(1:4,2:5,3:6,4:7,5:8,6:9,7:10), frequency = 4)
plot(ts)
有没有人遇到过同样的问题并设法解决了


我不确定我是否完全理解你想要实现的目标。但以下内容可能会有所帮助

您可以使用以下简单代码行:

这就产生了下面的简单图


完全正确,我将修复这些错误。谢谢
abline(a = 1, b = (ts[length(ts)]- ts[1]) / (length(ts)-1))
# your code
ts <- ts(c(1:4,2:5,3:6,4:7,5:8,6:9,7:10), frequency = 4)
plot(ts)

# drawing a blue line from (1, 1) to (8, 10)
lines(x = c(1, 8), y = c(1,10), col="blue")
ts <- ts(c(1:4,2:5,3:6,4:7,5:8,6:9,7:10), frequency = 4)
plot(ts, xlim=c(1,8), type="o")

x1 <- 1; y1 <- ts[1]
x2<- 7.75; y2 <- ts[length(ts)]

abline(a = y1-x1*(y1-y2)/(x1-x2), b = (y1-y2)/(x1-x2) )
grid()