我只有 4 个数据点:
points = c(60, 46, 46, 60)
Run Code Online (Sandbox Code Playgroud)
那个“想要”描述抛物线。不过,显然我找不到办法让它顺利。相反,我最终使用以下代码生成了下面红色的四四方方图:
plot(points, ylim=c(40,60), pch = 20, col = 2, cex = 2)
fit = loess(points ~ c(1:4), bw=nrd0, na.rm=T)
lines(predict(fit), lwd=2, col= 2)
Run Code Online (Sandbox Code Playgroud)
不知道有没有什么办法可以把边角弄光滑,让它看起来更像蓝线……
如您收到的消息所述,对loess这么少的点不满意。但是您可以使用spline以下方法获得漂亮的曲线:
points = c(60, 46, 46, 60)
plot(points, ylim=c(40,60), pch = 20, col = 2, cex = 2)
lines(spline(1:4, points, n=100))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3161 次 |
| 最近记录: |