R find the angle between two lines when they have slope and intercept coefficients

I have time:

x

4557  9940  9855  9894 10142  9501  9532  9229  9169  9214  9347  9176  8951  9344  9873  9970
9139  9420  9476  9205  9271  8632  8730  9336  9150  9601 10012  9841  9951  9222  8799  9316
10087  9677  9154  9019 10549  9629  9131  9560 10246 10982 11748  9054  8690  9923

tt<-1:length(x)

plot(x, xaxt = "n", type = "l", xlab = NULL, ylab = NULL, col = "royalblue2", lwd = 2.3)

I want to add a linear trend:

fit <- lm(x ~ tt)
co <- coef(fit)
co
    (Intercept)             tt 

    8940.23478           21.27031 

And then I need to find the angle between the two red lines:

abline(8940.23478, 21.27031, col = "red", lwd = 2)
abline(8940.23478, 0, col = "red", lwd = 2)

How can i do this?

Here is my schedule: Plot with two redlines

+3
source share
1 answer

Since your second slope 0, calculating the angle between this line and the slope is 21.27031very simple:

atan(21.27031) * 180 / pi

# [1] 87.30828

The angle between the line and the x axis is about 87 °.

+1
source

All Articles