Use R to graph a function with the plot command.
#create a simple x range
x <- seq(-5,5,0.1)
#define the function y=x^2
y <- x^2
#plot using base R
plot(x,y, type="l", col="green", lwd=2,
main="Graph of y=x^2",
xlab="x", ylab="y")
We say that \(f:X\ to\ Y\) is a
function if for every \(x \in X\) there
exists a UNIQUE \(y \in Y\) such that
\(f(x)=y\).
f <- function(x) x^3
curve(f,from = -4, to= 4, n=400,
xlab = "x", ylab = "y", lwd=2, col="pink",
main="Vertical Line Test: y=x^2 (Function)")
Define the function and graph it.
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.