gradient_plot: Plot a vector field

View source: R/vectorfield_plot.R

gradient_plotR Documentation

Plot a vector field

Description

Plot a vector field

Usage

gradient_plot(..., npts = 20, color = "black", alpha = 0.5, transform = sqrt)

vectorfield_plot(
  ...,
  npts = 20,
  color = "black",
  alpha = 0.5,
  transform = sqrt,
  env = NULL
)

Arguments

...

(Optional: a previous graphics layer), tilde expressions for horiz and vertical component of vectors, a domain (if not inherited from the graphics layer). The tilde expressions should be in the same style as for makeODE(). See details.

npts

number of arrows to draw in one row or column of the field.

color

character string specifying the color of the arrows.

alpha

transparency of the arrots

transform

controls the relative length of the arrows. See details.

env

Not for end-users. Handles details of where things are defined.

Details

There will be one tilde expression for the horizontal component of the vector and another tilde expression for the vertical component. Suppose the horizontal axis is called u and the vertical axis is called v, as would be established by a bounds specification like bounds(u=-1:1, v=-1:1). Then the horizontal tilde expression must have a left side called u ~. Similarly, the vertical tilde expression will have a left side called v ~. On the right side of the tilde expressions will go the formulas for the respective components of the vectors, e.g. u ~ sin(u-v) and v ~ v*u^2.

Typically, the length of the arrows is not meaningful in the units of the horizontal or vertical axis. For instance, in a gradient plot of f(x,y), the axis is in units of x, but the gradient component has units of f(x,y)/x. Similarly for the flow of a differential equation. Nonetheless, the relative lengths of the arrows, one to another, does have meaning. In drawing the vector field, the arrows are scaled so that the longest one barely avoids contact with it's neighbors. This natural scaling has the disadvantage that it can be hard to discern the lengths of the shortest arrows, which often are near zero (as with the gradient near the argmax or argmin, or near a fixed point of a differential equation flow field). By default, the relative lengths of the arrow are transformed by sqrt, to make the long arrows shorter and therefore enable the sort arrows to be drawn somewhat longer. If you want the natural scaling instead, use transform=I. Or you might want to make the arrows even more similar in length. Then use, for instance transform=function(L) L^0.1

Examples

gradient_plot(x * sin(y) ~ x & y, bounds(x=-1:1, y=-1:1), transform=I)
vectorfield_plot(x ~ -y, y ~ x, bounds(x=-1:1, y=-1:1))
gf_label(0 ~ 0, label="center", color="red") %>%
vectorfield_plot(x ~ -y, y ~ x, bounds(x=-1:1, y=-1:1), transform=function(x) x^0.2 )
vectorfield_plot(u ~ sin(u-v), v ~ v*u^2, bounds(u=0:1, v=-1:1))
 

mosaicCalc documentation built on Sept. 15, 2022, 9:06 a.m.