r语言 - 仅绘制拟合样条线,而不绘制数据点



我已经检查了我的参考文献,在我看来,要拟合具有x和y的数据集,许多教程需要首先绘制x和y,然后绘制拟合线。正常过程如下:

## Calculate the fitted line
smoothingSpline = smooth.spline(tree_number[2:100], jaccard[1:99], spar=0.35) 
plot(tree_number[2:100],jaccard[1:99]) #plot the data points
lines(smoothingSpline) # add the fitted spline line.

但是,我不想绘制tree_number和jaccard,而是只想在绘图中绘制拟合的样条线,我该怎么办?

您可以使用辅助绘图函数:

plot(smoothingSpline, type="l") 

或者,您可以显式提取xy值并绘制它们

plot(smoothingSpline$x, smoothingSpline$y, type="l")

为什么不干脆plot(smoothingSpline, type = "l")?这应该允许您添加拟合样条线,而无需先绘制数据点。

最新更新