使用行()绘图

时间:2018-02-20 21:00:24

标签: r time-series

这是我数据的前几行

> data
     Price       Time
1   116800 2008-03-01
2   117200 2008-04-01
3   125100 2008-05-01
4   125300 2008-06-01
5   128700 2008-07-01
6   132900 2008-08-01
7   133500 2008-09-01
8   133700 2008-10-01
9   122900 2008-11-01

我尝试将其作为时间序列进行操作并绘制我的二次模型,但失败了,这是我的代码:

t<-time(data$Time)
tsquare<-t^2
fit1<-lm(Price~t+tsquare,data=data)
plot(x=data$Time,y=data$Price,type="l",main="New Orleans House Price Trend S 
ince 2008",xlab="Time",ylab = "Price")
lines(y=fit1$fitted.values,x=as.vector(t), type='l',col="red")

这是错误:

Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet

The code runs without error but there is no red line pops up

0 个答案:

没有答案