# ------------------------------------------------------------------
# File name: add_to_plot.R
#
# plot() is a high-level plotting function that opens a new plotting window
# using low-level functions, one can add to the open plot
# some of the commonly used adding functions are:
# points(), lines(), abline(), legend(), text()
# Below, we will plot a function and add to plot
# its inverse function, a line, text, and a legend
#
# Version: 2.1
# Authors: H. Kocak, University of Miami and B. Koc, Stetson University
# References:
# https://www.r-project.org
# ------------------------------------------------------------------
t = seq(from = 0, to = 10, by = 0.5)
# To pause between plots
par(ask = TRUE)
plot (t, sqrt(2 * t), main = "Adding to Plot", sub = "A function and its inverse",
xlab = "", ylab = "", xlim = c(0, 10), ylim = c(0, 10), pch = 16, type = "o")
# To add the inverse function
points(t, 0.5 * t * t, col = "red" , pch = 16, type = "o")
# To add the line with intercept = 0, slope = 1
abline(0, 1, col = "gray", lwd = 3, lty = "dashed")
# To add text
text(7, 7.3, "45-degree line", srt = 45)
legend("bottomright", legend = c("funtion", "inverse"), pch = 16, col = c("black", "red"))
# One can add graphs of mathematical functions using, for example:
# lines(curve(sin(x) + cos(x) + 5, add = TRUE))