draw_gradient: Draw gradient arrows on a plot made with...

Description Usage Arguments Details Examples

View source: R/draw_gradient.R

Description

Draw gradient arrows on a plot made with mosaicCalc::contour_plot()

Usage

1
draw_gradient(P = NULL, f, x, y, scale = 0.1, color = "red")

Arguments

P

The contour plot. Typically, you will pipe the contour_plot() command into draw_gradient() and so you can ignore this argument: the piping process will fill it in.

f

the mathematical function of two inputs whose gradient is to be displayed.

x

Numerical value(s) of the x-coordinate at which to evaluate the gradient.

y

Similar to x

scale

A numerical fudge factor so that the gradient arrows can be scaled to look neither overlong nor overshort on the graph.

color

Default "red"

Details

Depending on the relative extent of the x and y axes, the gradient arrows may not appear to the eye orthogonal to the contour lines, even though they are numerically. Use coord_fixed() as shown in the example to fix this graphical artifact.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
library(mosaicCalc)
library(mosaic)
library(ggformula)
landscape <- rfun( ~ x + y, seed = 101)
contour_plot(landscape(x, y) ~ x + y, domain(x=c(-5,5), y = c(-5, 5))) %>%
  draw_gradient(landscape, x = -5:5, y = 5:-5, scale=1 )  %>%
  gf_refine(coord_fixed())

## End(Not run)

dtkaplan/mosaicUSAFA documentation built on Aug. 21, 2021, 10:37 p.m.