我想在R中计算(而非绘制)2D样条路径。有一个旧问题涉及到这个主题,建议使用 xspline()
: Calculate a 2D spline curve in R
xspline()
对于我的目的来说有些限制:
- 我不能自定义插值点的数量
- 即使我不想绘制任何东西,我也需要调用
plot.new()
- 我只有一个参数(形状)用于自定义样条; 如果可能的话,我想尝试几种不同的类型
可重现的示例:
library(ggplot2)
# control points
x <- c(.1, .5, .7, .8)
y <- c(.9, .6, .5, .1)
plot.new() # necessary for xspline(); would be great if it could be avoided
# how do I set the number of interpolation points?
# how do I modify the exact path (beyond shape parameter)?
path <- xspline(x, y, shape = 1, draw = FALSE)
# plot path (black) and control points (blue) with ggplot
ggplot(data = NULL, aes(x, y)) +
geom_point(data = as.data.frame(path), size = 0.5) +
geom_point(data = data.frame(x, y), size = 2, color = "blue")
该内容由reprex包(v2.0.0)于2021年08月14日创建
有没有xspline()
的易于获取的替代品?
spline
- 请看我的更新。 - Allan Cameron