plotFunction: Surface plot of a function

View source: R/plotFunction.R

plotFunctionR Documentation

Surface plot of a function

Description

A (filled) contour plot or perspective / surface plot of a function.

Usage

plotFunction(
  f = function(x) {
     rowSums(x^2)
 },
  lower = c(0, 0),
  upper = c(1, 1),
  type = "filled.contour",
  s = 100,
  xlab = "x1",
  ylab = "x2",
  zlab = "y",
  color.palette = terrain.colors,
  title = " ",
  levels = NULL,
  points1,
  points2,
  pch1 = 20,
  pch2 = 8,
  lwd1 = 1,
  lwd2 = 1,
  cex1 = 1,
  cex2 = 1,
  col1 = "red",
  col2 = "black",
  theta = -40,
  phi = 40,
  ...
)

Arguments

f

function to be plotted. The function should either be able to take two vectors or one matrix specifying sample locations. i.e. z=f(X) or z=f(x2,x1) where Z is a two column matrix containing the sample locations x1 and x2.

lower

boundary for x1 and x2 (defaults to c(0,0)).

upper

boundary (defaults to c(1,1)).

type

string describing the type of the plot: "filled.contour" (default), "contour", "persp" (perspective), or "persp3d" plot. Note that "persp3d" is based on the plotly package and will work in RStudio, but not in the standard RGui.

s

number of samples along each dimension. e.g. f will be evaluated s^2 times.

xlab

lable of first axis

ylab

lable of second axis

zlab

lable of third axis

color.palette

colors used, default is terrain.color

title

of the plot

levels

number of levels for the plotted function value. Will be set automatically with default NULL.. (contour plots only)

points1

can be omitted, but if given the points in this matrix are added to the plot in form of dots. Contour plots and persp3d only. Contour plots expect matrix with two columns for coordinates. 3Dperspective expects matrix with three columns, third column giving the corresponding observed value of the plotted function.

points2

can be omitted, but if given the points in this matrix are added to the plot in form of crosses. Contour plots and persp3d only. Contour plots expect matrix with two columns for coordinates. 3Dperspective expects matrix with three columns, third column giving the corresponding observed value of the plotted function.

pch1

pch (symbol) setting for points1 (default: 20). (contour plots only)

pch2

pch (symbol) setting for points2 (default: 8). (contour plots only)

lwd1

line width for points1 (default: 1). (contour plots only)

lwd2

line width for points2 (default: 1). (contour plots only)

cex1

cex for points1 (default: 1). (contour plots only)

cex2

cex for points2 (default: 1). (contour plots only)

col1

color for points1 (default: "black"). (contour plots only)

col2

color for points2 (default: "black"). (contour plots only)

theta

angle defining the viewing direction. theta gives the azimuthal direction and phi the colatitude. (persp plot only)

phi

angle defining the viewing direction. theta gives the colatitude. (persp plot only)

...

additional parameters passed to contour or filled.contour

See Also

plotData, plotModel

Examples

plotFunction(function(x){rowSums(x^2)},c(-5,0),c(10,15))
plotFunction(function(x){rowSums(x^2)},c(-5,0),c(10,15),type="contour")
plotFunction(function(x){rowSums(x^2)},c(-5,0),c(10,15),type="persp")


SPOT documentation built on June 26, 2022, 1:06 a.m.