如何在ggplot2中使用spline平滑算法

smooth.spline2 <- function(formula, data, ...) {
mat <- model.frame(formula, data)
smooth.spline(mat[, 2], mat[, 1])
}

predictdf.smooth.spline <- function(model, xseq, se, level) {
pred <- predict(model, xseq)
data.frame(x = xseq, y = pred$y)
}

qplot(mpg, wt, data = mtcars) + geom_smooth(method = "smooth.spline2", se= F)

spline是很好的连接点之后将其平滑的算法,但是ggplot中不能直接用,这里提供了一个子函数,可以使用spline让曲线平滑,非常好用。

原网址:http://www.lgbmi.com/2011/10/using-smooth-spline-in-stat-scale-in-ggplot2/

原文地址:https://www.cnblogs.com/yumtaoist/p/3798240.html