Plotting lines

You can use the curve function to plot a line graph of a function. If that function were \(f(x) = x^2\) for example, you would type this:

curve(x^2, from = -5, to = 5, n = 500, col = "red", ylab = "f(x)")

This function takes many arguments.

curve(x^2, from = -5, to = 5, n = 5)

If you want multiple lines on one graph, you can call curve multiple times, and include the add argument in all but the first call:

curve(1*x^2, from = -5, to = 5, n = 500, col = "red", ylab = "")
curve(2*x^2, from = -5, to = 5, n = 500, col = "blue", ylab = "", add = TRUE)
curve(3*x^2, from = -5, to = 5, n = 500, col = "darkgreen", ylab = "", add = TRUE)
legend("bottomleft", c("a = 1", "a = 2", "a = 3"), 
       col = c("red", "blue", "darkgreen"), lty = 1, bty = "n")