Learn R Programming

mosaic (version 0.3-13)

plotFun: Plotting mathematical expressions

Description

Plots mathematical expressions in one and two variables.

Usage

plotFun(object, ..., add = FALSE, xlim = NULL,
    ylim = NULL, npts = NULL, ylab = NULL, xlab = NULL,
    zlab = NULL, main = NULL, lwd = 1, col = "black",
    filled = TRUE, levels = NULL, nlevels = 10,
    surface = FALSE, colorscheme = topo.colors, type = "l",
    transparency = NULL)

Arguments

object
a mathematical expression (see examples)
...
additional assignments to parameters and limits
add
if TRUE, then overlay an existing plot
xlim
limits for x axis (or use variable names, see examples)
ylim
limits for y axis (or use variable names, see examples)
npts
number of points for plotting.
xlab
label for x axis
ylab
label for y axis
zlab
label for z axis (when in surface-plot mode)
main
main label for plot
lwd
line width for line graphs and contours
col
color for line graphs and contours
filled
fill with color between the contours (TRUE by default)
levels
levels at which to draw contours
nlevels
number of contours to draw (if levels not specified)
surface
draw a surface plot rather than a contour plot
colorscheme
function (topo.colors by default) for choosing colors for fill
type
type of plot ("l" by default)
transparency
number from 0 (transparent) to 1 (opaque) for the fill colors

Value

  • an R function for the expression being plotted (not a graphics object)

Details

makes plots of mathematical expressions using the formula syntax. Will draw both line plots and contour/surface plots (for functions of two variables) In RStudio, the surface plot comes with sliders to set orientation. If the colors in filled surface plots are two blocky, increase npts beyond the default of 50. npts=300 is as much as you're likely to every need See examples for overplotting a constraint function on an objective function.

Examples

Run this code
plotFun(a*sin(x^2)~x, xlim=range(-5,5), a=2)
f <- rfun( ~ u & v)
plotFun( f(u=u,v=v) ~ u & v, u.lim=range(-3,3), v.lim=range(-3,3) )
plotFun( u^2 + v < 3 ~ u & v, add=TRUE, npts=200)

Run the code above in your browser using DataLab