Learn R Programming

barsurf (version 0.5.0)

02_scalar_fields_continuously-spaced: Continuously-Spaced Scalar Fields

Description

Plots of functions of two variables (which can be mapped to continuously-spaced scalar fields), for both rectangular and triangular areas.

Usage

#x-y-fv versions
#(main argument is a matrix)
plot_cfield (x, y, fv, fb, …,
    contours=TRUE, heatmap=TRUE, contour.labels=FALSE,
    main, xlab="x", ylab="y", xat, yat, xlabs, ylabs,
    xyrel = test.xyrel (x, y, fv),
    add=FALSE, axes=TRUE, reverse=FALSE,
    ncontours=6, clabs,
    contour.color="#000000",
    color.function, color.fit, hcv=FALSE)

plot_surface (x, y, fv, …, grid.lines=TRUE, main, xlab="x", ylab="y", xat, yat, xlabs, ylabs, zlim, axes=TRUE, arrows=TRUE, grid.color, color.function, color.fit)

plot_tricontour (x, y, fv, fb, …, contours=TRUE, heatmap=TRUE, contour.labels=FALSE, main, xlab="x", ylab="y", xyrel="s", axes=TRUE, ncontours=6, clabs, contour.color="#000000", color.function, color.fit, hcv=FALSE)

plot_trisurface (x, y, fv, …, grid.lines=TRUE, main, xlab="x", ylab="y", zlim, axes=TRUE, arrows=TRUE, grid.color, color.function, color.fit)

#functional versions #(which call the x-y-fv versions above) plotf_cfield (f, xlim, ylim=xlim, …, n=30) plotf_surface (f, xlim, ylim=xlim, zlim, …, n=30) plotf_tricontour (f, …, n=30) plotf_trisurface (f, …, n=30)

Arguments

x, y

Optional sorted numeric vectors of x and y coordinates, refer to details. In the triangular case, ignored.

fv

A numeric matrix (representing a continuously-spaced scalar field), which may not include NAs. In the triangular case, fv needs to be a square matrix, but only the top-left triangle is used, including the diagonal.

fb

Optional numeric vector of function values (or "levels"), for contours.

grid.lines

Logical, include grid lines.

contours

Logical, include contour lines.

heatmap

Logical, include heatmap.

contour.labels

Logical, include contour labels.

main, xlab, ylab

Optional strings, main/axes titles.

xat, yat

Optional numeric vectors, the x and y axes tick points.

xlabs, ylabs

Optional character vectors, the x and y axes tick labels. In 3D plots, ignored unless axes is true and arrows is false.

xyrel

Single character, either "f", "s" or "m". "f" produces a plot with a fixed aspect ratio of one, "s" produces a square plot, and "m" a maximized plot.

add

Logical, if true add contours/heatmap to an existing plot.

axes

Logical vector of length one or two, if true plot reference arrows or axis ticks with labels.

arrows

Logical vector of length one or two, (subject to axes, above) if true, plot reference arrows, if false, use axis ticks with labels.

reverse

Logical vector of one or two, to reverse the x and y axes. Note that this argument could change.

ncontours

Integer, the number of contour lines. Ignored if fb supplied.

clabs

Optional character vector of contour labels.

grid.color

String, giving the grid line color.

contour.color

Character vector of length one or with the same length as the number of contours, giving the contour line colors.

color.function

Optional color function, such as an arbitrary litmus object (for plot_surface) or an opaque litmus object (for the other plots), refer to details.

color.fit

Optional color fitting function, such as a litmus.fit wrapper, refer to details.

hcv

Logical, use the high color variation option, refer to details.

f

In the rectangular case, a numeric-valued function of two variables (x and y), suitable for use with base::outer. In the triangular case, a similar function, but of three variables (w1, w2, w3) or (x, y and z) etc, with values between zero and one, which in general, sum to one.

xlim, ylim

Length-2 numeric vectors, the x and y ranges. Currently, these need to be ascending.

zlim

Length-2 numeric vector, the vertical range, corresponding to the value of the function or matrix.

n

An integer vector of length one or two, giving the number of grid points.

In the x-y-fv versions, ignored.

Details

These functions produce combined contour-heat plots and 3d surface plots, for rectangular (and triangular) continuously-spaced scalar fields.

This can be used to plot numeric matrices (here, labelled as fv), and functions that can be mapped to numeric matrices.

In contrast to the discretely-spaced case, each heatmap bin represents one area between four (or three) fv points.

Increasing rows in fv correspond to increasing x values and increasing columns in fv correspond to increasing y values. If the x vector is supplied its length needs to equal the number of rows. Likewise, if the y vector is supplied its length needs to equal the number of columns.

Currently, surface plots use a diamond-based projection with a fixed viewing angle, such that the origin is at the bottom center.

If none of color.function and color.fit are supplied, then: (1) A color.fit function is determined by global options. (2) The color.fit function is used to compute a color.function from interpolated bin values (in heatmaps) or the magnitudes of their gradients (for surface plots). (3) The color.function is used to compute a color matrix from the interpolated bin values or magnitudes.

The color function can be any function that maps a numeric vector/matrix to a character vector/matrix of R colors, however, I recommend using litmus objects. The color fit function can be any function that maps a numeric vector to a valid color function, however, I recommend using a litmus.fit wrapper.

Note that: (1) In the plot_* functions (not the plotf_* functions) the only argument that's required is fv. (2) There's no guarantee that default contour lines will be suitable. (3) If using plot_surface or plot_trisurface to plot near-constant values, set zlim, for a better result. (4) In publication graphics, you may want to increase the resolution of the heatmap. (5) Only opaque color functions should be used in heatmaps, that is, color functions that produce opaque colors with no transparency. However, surface plots may use semitransparent colors.

Expanding on point (3), functions that are constant in theory, may product non-constant (but near-constant) values when computed via floating point arithmetic.

References

Refer to the vignette for an overview, references and better examples.

See Also

Discretely-spaced versions: plot_dfield

Plots of scalar fields over three variables: plot_contour_3d, plot_cfield_3d

Other functions: litmus, litmus.fit

test.xyrel

Examples

Run this code
# NOT RUN {
x <- y <- seq (-15.5, 15.5, length.out=40)
fv <- outer (x, y, rotated.sinc)

plot_cfield (,,fv)
plot_surface (,,fv)
# }

Run the code above in your browser using DataLab