Using R, I would like to plot a linear relationship between two variables, but I would like the fitted line to be present only within the range of the data.
For exam
You can do this using predict.
You can predict on specific values of x (see ?predict)
x<-1:10 y<-1:10 plot(x,y) new <- data.frame(x = seq(1, 5, 0.5)) lines(new$x, predict(lm(y~x), new))