Learn R Programming

sdetorus (version 0.1.10)

plotSurface2D: Contour plot of a 2D surface

Description

Convenient wrapper for plotting a contour plot of a real function of two variables.

Usage

plotSurface2D(x = seq_len(nrow(z)), y = seq_len(ncol(z)), f, z = NULL,
  nLev = 20, levels = NULL, fVect = FALSE, ...)

Value

The matrix z, invisible.

Arguments

x, y

numerical grids fore each dimension. They must be in ascending order.

f

function to be plot. Must take a single argument (see examples).

z

a vector of length length(x) * length(y) containing the evaluation of f in the bivariate grid. If not provided, it is computed internally.

nLev

the number of levels the range of z will be divided into.

levels

vector of contour levels. If not provided, it is set to quantile(z, probs = seq(0, 1, l = nLev)).

fVect

flag to indicate whether f is a vectorized function (see examples).

...

further arguments passed to image

Examples

Run this code
# \donttest{
grid <- seq(-pi, pi, l = 100)
plotSurface2D(grid, grid, f = function(x) sin(x[1]) * cos(x[2]), nLev = 20)
plotSurface2D(grid, grid, f = function(x) sin(x[, 1]) * cos(x[, 2]),
              levels = seq(-1, 1, l = 10), fVect = TRUE)
# }

Run the code above in your browser using DataLab