tangents | R Documentation |
Draw tangent lines to an existing plot.
tangents(x, y, slope, length = 1, ...)
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 |
The length of the tangent lines is scaled according to the current aspect ratio of the existing plot.
Carmen van Meegen
segments
for drawing line segments between pairs of points.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.