Q:

Adding two regression graphs having problem in dots and lines

I cannot find my answer anywhere.
I have two regression lines from two different datasets. I am trying to put these two regression lines in one graph. The following worked well.
regression1<-lm(Y ~ X, data = mydata1) 
regression2<-lm(Y ~ X, data = mydata2)
abline(regression1)
abline(regression2)

However in this plot I just have lines and I don't have dots. I run:
regression1<-lm(Y ~ X, data = mydata1)
regression2<-lm(Y ~ X, data = mydata2)
plot(c(0,2),c(0,2),type="n") +
points(rnorm(200), rnorm(200), col = "red") 
abline(regression1) 
abline(regression2)

With this command, I had just dots and I don't have lines, still does not work for me. What I want is having one graph with two different lines (representing the each regression's fitted lines) and dots of these regressions. I want these with different colours. Any help would be appreciated. Thanks

A:

When, using base R graphics, you plot something and it doesn't show up in the graph the odds are that you have plotted it outside the plot area. In the example below I will make sure that everything is in the plot area by first getting appropriate x and y axis limits.   
The first two code lines do the trick.
rangeX <- range(c(mydata1$X, mydata2$X))
rangeY <- range(c(mydata1$Y, mydata2$Y))

regression1 <- lm(Y ~ X, data = mydata1)
regression2 <- lm(Y ~ X, data = mydata2)
plot(rangeX, rangeY, type = "n", xlab = "X", ylab = "Y")
with(mydata1, points(X, Y, col = "red"))
with(mydata2, points(X, Y, col = "blue"))
abline(regression1, col = "red")
abline(regression2, col = "blue")

Data creation code. 
set.seed(1234)

n <- 20
x <- seq_len(n) + rnorm(n)
mydata1 <- data.frame(X = x, Y = x + rnorm(n))
x <- seq_len(n) + rnorm(n)
mu <- 3
mydata2 <- data.frame(X = x + rnorm(n), Y = mu + x + rnorm(n))

