Drop-in replacement for stats::approx.
Uses the Catmull-Rom spline (with the same smoothing
parameter as Highcharts type = "spline") instead of straight-line
segments. The call signature and return value are identical to
stats::approx, so it can be substituted transparently.
Usage
approx.spline(
x,
y = NULL,
xout = NULL,
n = 50,
rule = 1,
log = FALSE,
smoothing = 1.5,
...
)Arguments
- x
Numeric vector of abscissa values.
- y
Numeric vector of ordinate values, same length as
x.- xout
Optional numeric vector of points where the spline is evaluated. If
NULL, a regular grid of lengthnis used.- n
Integer. Number of points to generate when
xoutisNULL. Default is 50.- rule
Handling of points outside the range of
x.1returnsNA;2repeats the nearest endpoint value. Matches the semantics ofstats::approx.- log
Logical. If
TRUE, interpolation is performed in log-log space. Default isFALSE.- smoothing
Numeric tension parameter used in the Catmull-Rom to Bezier conversion. Default is 1.5 (Highcharts default).
- ...
Additional arguments ignored; present only for full signature compatibility with
stats::approx.
Value
A list with components x and y, just like
stats::approx.
Examples
x <- c(0.05, 0.10, 0.20, 0.30, 0.50, 1.0, 2.0, 3.0)
y <- exp(-x)
Td <- seq(0.05, 3.0, length.out = 100)
approx.spline(x, y, xout = Td, log = TRUE)$y
#> [1] 0.95122942 0.92298087 0.90776491 0.89006474 0.85611788 0.81992556
#> [7] 0.82664406 0.79806681 0.75706097 0.74457432 0.73689817 0.71800798
#> [13] 0.69295627 0.66515366 0.63680013 0.60925220 0.61121472 0.60973509
#> [19] 0.60268370 0.59140399 0.57703021 0.56049496 0.54254877 0.52378438
#> [25] 0.50466179 0.48553158 0.46665573 0.44822536 0.43037563 0.41319798
#> [31] 0.39675000 0.38106346 0.36879806 0.37502227 0.37866764 0.37994948
#> [37] 0.37910191 0.37636695 0.37198593 0.36619303 0.35921049 0.35124547
#> [43] 0.34248809 0.33311049 0.32326657 0.31309242 0.30270707 0.29221347
#> [49] 0.28169979 0.27124064 0.26089839 0.25072453 0.24076082 0.23104054
#> [55] 0.22158956 0.21242731 0.20356773 0.19502005 0.18678952 0.17887808
#> [61] 0.17128488 0.16400679 0.15703885 0.15037462 0.14400647 0.13792591
#> [67] 0.13868766 0.14387525 0.14800098 0.15105744 0.15306292 0.15405768
#> [73] 0.15409982 0.15326124 0.15162364 0.14927488 0.14630573 0.14280707
#> [79] 0.13886766 0.13457228 0.13000040 0.12522526 0.12031323 0.11532358
#> [85] 0.11030843 0.10531289 0.10037541 0.09552814 0.09079749 0.08620458
#> [91] 0.08176585 0.07749354 0.07339627 0.06947950 0.06574600 0.06219630
#> [97] 0.05882902 0.05564130 0.05262900 NA