Learn R Programming

barsurf (version 0.5.0)

05_vector_fields: Vector Fields

Description

Plots of vector fields.

Usage

#x-y-fx-fy version
#(main arguments are matrices)
plot_vecfield (x, y, fx, fy, …,
    vectors=TRUE, heatmap=TRUE, all=FALSE,
    main, xlab="x", ylab="y", xat, yat, xlabs, ylabs,
    xyrel = test.xyrel (x, y, fv),
    add=FALSE, axes=TRUE, reverse=FALSE,
    arrowh.length=1.75, arrowh.width = 0.75 * arrowh.length,
    arrow.color="#000000", fill.color="#08080810",
    color.function, color.fit, hcv=FALSE)

#functional version #(which calls the x-y-fx-fy version above) plotf_vecfield (f, xlim, ylim=xlim, …, nv=20, nh=40)

Arguments

x, y

Optional sorted numeric vectors of x and y coordinates, refer to details.

fx, fy

Numeric matrices (representing x and y components of a vector field), which may include NAs.

vectors

Logical, include vector arrows.

heatmap

Logical, include heatmap.

all

Logical, plot all vector arrows. Otherwise (the default), exclude the outermost rows and columns.

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.

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 axis ticks with labels.

reverse

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

arrowh.length

Arrow head length, in mm.

arrowh.width

Arrow head width, in mm.

arrow.color

Arrow line color.

fill.color

Arrow fill color.

color.function

Optional color function, such as an opaque litmus object, 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

A function of two variables (x and y), which returns a list of two numeric vectors, one value for the x component and one for the y component.

xlim, ylim

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

nv, nh

Integer vectors of length one or two, giving the number of grid points, where nv is for the vector arrows and nh is for the heatmap.

In the x-y-fx-fy version, ignored.

Details

Refer to plot_cfield for background information.

The plot_vecfield function is the same, except that: (1) There are vector arrows rather than contour lines. (2) fv is replaced by two matrices, for the x and y components. (3) The color of the heatmap is determined by the magnitude of the vectors, similar to plot_surface. (4) Missing values are allowed.

The plotf_vecfield function calls plot_vecfield twice, and by default, uses a higher resolution for the heatmap than the arrows.

If you want to plot a vector field with a subset of vector arrows then I recommend you plot the vector field with vectors=FALSE, then plot another vector field on top of it with add=TRUE, heatmap=FALSE, and set parts of fx or fy to NA. A similar approach can be used to plot vector fields with arrows that have different sizes or colors.

Note that: (1) In the plot_vecfield the only arguments that are required are fx and fy. (2) In publication graphics, you may want to increase the resolution of the heatmap. (3) Only opaque color functions should be used, that is, color functions that produce opaque colors with no transparency.

References

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

See Also

plot_cfield

litmus, litmus.fit

test.xyrel

Examples

Run this code
# NOT RUN {
plotf_vecfield (concentric.field, c (-1.5, 1.5), c (-1.5, 1.5) )
# }

Run the code above in your browser using DataLab