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
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
))