r - Add a segment of a regression line to a plot -


i have 4 regression lines , want have them in 1 plot. here 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 plot: regression plot

but not want have. black line fine, red, blue , green lines, want have segment of lines close data points. example, segment of green line between 3 , 4. datasets 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

one way use clip:

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) clip(min(data1$v1), max(data1$v1), min(data1$v2), max(data1$v2)) fit1 <- lm(data1$v2~data1$v1) abline(fit1, col=2)  data2 = read.csv("test2.csv", header = false) clip(min(data2$v1), max(data2$v1), min(data2$v2), max(data2$v2)) fit2 <- lm(data2$v2~data2$v1) abline(fit2, col=3)  data3 = read.csv("test3.csv", header = false) clip(min(data3$v1), max(data3$v1), min(data3$v2), max(data3$v2)) fit3 <- lm(data3$v2~data3$v1) abline(fit3, col=4) 

so, i'm doing limiting fitted line-plots respective data-set ranges. limits extremely tight, can rescaled fitted lines extend bit outside data-set ranges.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -