A (filled) contour plot or perspective / surface plot of a function.
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,
...
)
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
.
boundary for x1 and x2 (defaults to c(0,0)
).
boundary (defaults to c(1,1)
).
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.
number of samples along each dimension. e.g. f
will be evaluated s^2
times.
lable of first axis
lable of second axis
lable of third axis
colors used, default is terrain.color
of the plot
number of levels for the plotted function value. Will be set automatically with default NULL.. (contour plots only)
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.
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.
pch (symbol) setting for points1 (default: 20). (contour plots only)
pch (symbol) setting for points2 (default: 8). (contour plots only)
line width for points1 (default: 1). (contour plots only)
line width for points2 (default: 1). (contour plots only)
cex for points1 (default: 1). (contour plots only)
cex for points2 (default: 1). (contour plots only)
color for points1 (default: "black"). (contour plots only)
color for points2 (default: "black"). (contour plots only)
angle defining the viewing direction. theta gives the azimuthal direction and phi the colatitude. (persp plot only)
angle defining the viewing direction. theta gives the colatitude. (persp plot only)
additional parameters passed to contour
or filled.contour
# NOT RUN {
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")
# }
Run the code above in your browser using DataLab