Q: Abline with time series in x-axis (R) I would like to add a line with intercept =37 and a slope = 5 in abline. The problem is that the x-axis are the date from a ts object. I would like the line start to the first time period (intercept=37 for x= 2013first quarter)
cars<-c(21,22,18,25,14,23,27,18,21,15,24,27,20,25,18,20)
cars<-ts(cars, start=c(2013, 1), end=c(2016, 4),frequency=4)
plot(cars)
abline(a=37.95, b=4.29)


A: If you need to plot a line with intercept 37.95 at 2013 and slope b=4.29, you need to solve the following simple equation:
39.75 = a + 4.29 * 2013
a = -8597.82

Thus:
cars <- c(21,22,18,25,14,23,27,18,21,15,24,27,20,25,18,20)
cars <- ts(cars, start=c(2013, 1), end=c(2016, 4),frequency=4)
plot(cars, ylim=c(14,60))
abline(a=-8597.82, b=4.29)


