vc_plot_secant: Plot an interactive secant and its function

View source: R/plot_local_models.R

vc_plot_secantR Documentation

Plot an interactive secant and its function

Description

Display sampled function values and a local line with Plotly. Computation is performed separately by vc_secant(), vc_tangent(), or vc_differential().

Usage

vc_plot_secant(
  result,
  f,
  xlim = NULL,
  n = 401L,
  colors = c(curve = "#24476b", line = "#c44736", point = "#222222", differential =
    "#188367", change = "#8250a3"),
  title = NULL,
  xlab = "x",
  ylab = "y"
)

Arguments

result

Plain result list from the corresponding calculation function.

f

The same deterministic scalar function used for the calculation. Function values at the stored anchor points must match the result.

xlim

Optional increasing pair of finite real plot limits, containing the anchor points. NULL derives limits around the anchors.

n

Integer number of curve samples, at least 2. The curve is a sampled visualization, not an exact representation or a continuity test.

colors

Named character vector with entries curve, line, point, differential, and change; values are Plotly/CSS colors.

title

Optional scalar plot title. NULL uses a descriptive default.

xlab, ylab

Scalar axis labels.

Details

Function samples that raise errors or produce nonfinite/nonreal scalar values are gaps; warnings during curve sampling are suppressed. The plot fails if no finite sample exists. Finite samples across an unresolved discontinuity can still be joined: users must choose a suitable domain and sampling resolution. The anchor points are checked strictly. Graphical limits and line evaluations must be finite.

Value

An interactive plotly htmlwidget. Zoom, pan, hover and legend controls are available. No derivative calculation is performed here.

Examples

if (requireNamespace("plotly", quietly = TRUE)) {
  f <- function(x) x^2
  vc_secant(f, 1, 2) |> vc_plot_secant(f = f)
}

vectorialcalculus documentation built on Nov. 17, 2026, 1:09 a.m.