I have 4 regression lines and I want to have them in one plot. Here is my simple code:
data = read.csv("TEST.csv", header = FALSE)
plot(data$V1,data$V2)
fit <- lm(data$V2~data$V1)
abline(fit, col=1)
data1 = read.csv("TEST1.csv", header = FALSE)
fit1 <- lm(data1$V2~data1$V1)
abline(fit1, col=2)
data2 = read.csv("TEST2.csv", header = FALSE)
fit2 <- lm(data2$V2~data2$V1)
abline(fit2, col=3)
data3 = read.csv("TEST3.csv", header = FALSE)
fit3 <- lm(data3$V2~data3$V1)
abline(fit3, col=4)
and here is the plot:
but it is not what I want to have. The black line is fine, but for red, blue and green lines, I just want to have a segment of those lines close to the data points. For example, just a segment of green line between 3 and 4. Datasets are located here :
TEST.csv: https://www.dropbox.com/s/aphd5ts9hxlm2wj/TEST.csv?dl=0
TEST1.csv: https://www.dropbox.com/s/dp3diwu4tuynbjp/TEST1.csv?dl=0
TEST2.csv: https://www.dropbox.com/s/b6zr88ottf3wmjg/TEST2.csv?dl=0
TEST3.csv: https://www.dropbox.com/s/o0qc2987gb04g7m/TEST3.csv?dl=0
dput( data[ c("V1",V2")
AND the code that was used to build thefit_n
's - IRTFM