Graphics Reference
In-Depth Information
See Also
For more on making basic box plots, see Making a Basic Box Plot .
Plotting a Function Curve
Problem
You want to plot a function curve.
Solution
To plot a function curve, as in Figure 2-12 , use curve() and pass it an expression with the vari-
able x :
curve(x ^ 3 - 5 * x, from = -4 , to = 4 )
Figure 2-12. Left: function curve with base graphics; right: with user-defined function
You can plot any function that takes a numeric vector as input and returns a numeric vector,
including functions that you define yourself. Using add=TRUE will add a curve to the previously
created plot:
# Plot a user-defined function
myfun <- function
function (xvar) {
1 / ( 1 + exp( - xvar + 10 ))
Search WWH ::




Custom Search