f <- function(x) cos(x)
f_t <- function(x) -(x-(pi/2)) + (1/6)*(x-(pi/2))^3

# Setup x range
x <- seq(0, pi, by = 0.1)

# Create the plot
plot(x, f(x), type = "l", ylim = c(-5, 5), ylab = "y", xlab = "x", main = "Multiple Function Plot")
lines(x, f(x), col = "blue")
lines(x, f_t(x), col = "green")

# Add a legend
legend("topright", legend = c("f(x)", "Taylor approx."), col = c("blue", "green"), lty = 1, cex = 0.8)