tangents {gek} | R Documentation |
Add Tangent Lines to a Plot
Description
Draw tangent lines to an existing plot.
Usage
tangents(x, y, slope, length = 1, ...)
Arguments
x , y |
coordinate vectors of points |
slope |
vector of slopes at the points |
length |
desired length of tangent lines, see ‘Details’. |
... |
further graphical parameters to be passed to |
Details
The length of the tangent lines is scaled according to the current aspect ratio of the existing plot.
Author(s)
Carmen van Meegen
See Also
segments
for drawing line segments between pairs of points.
Examples
# Define test function and its gradient from Oakley and O'Hagan (2002)
f <- function(x) 5 + x + cos(x)
fGrad <- function(x) 1 - sin(x)
# Generate coordinates and calculate slopes
x <- seq(-5, 5, length = 5)
y <- f(x)
dy <- fGrad(x)
# Draw curve and tangent lines
curve(f(x), from = -6, to = 6)
tangents(x, y, dy, length = 2, lwd = 2, col = 2:6)
points(x, y, pch = 16)
[Package gek version 1.1.0 Index]