Adding points

To add points to an existing plot, use points()

n = 50
set.seed(0)
x = sort(runif(n, min=-2, max=2)) 
y = x^3 + rnorm(n)
plot(x, y)
points(x, x^3, pch=20, col="red")

Adding lines

To add lines to an existing plot, use lines()

plot(x, y)
lines(x, x^3, col="red")

points() and lines() can be called multiple times

These functions can be called repeatedly, to continue adding to the current plotting window

plot(x, y)
lines(x, x^3, col=2)
lines(x, x^3 + qnorm(0.90), col=3)
lines(x, x^3 + qnorm(0.10), col=4)

Adding straight lines

To add a line of the form \(y = a+bx\) to an existing plot, use abline(). Can also add vertical or horizontal lines. Lastly, can set line type, width, and color, as usual

plot(x, y)
abline(a=0, b=3)
abline(h=0, lty=2, lwd=3, col="red")