I am unable to reproduce your error, and the code works fine for me in RStudio:
x <- lynx[1:20]
y <- lynx[21:40]
z <- lynx[41:60]
plot(x, col = "blue", pch = 20)
points(y, pch = 20, col = "red")
points(z, pch = 20, col = "green")
legend(14, 6000, cex = 0.8,
col = c("blue", "red", "green"),
pch = 20,
legend = c("1821-1840",
"1841-1860",
"1861-1880"))

Created on 2018-06-07 by the reprex package (v0.2.0).