Если вы прочитаете исходный код для scatter.smooth
, вы обнаружите, что линия предсказания строится без параметра col
.
Это означает, что вам придется изменить код. Здесь я добавляю lcol
аргумент для цвета линии:
scatter.smooth <- function (x, y = NULL, span = 2/3, degree = 1,
family = c("symmetric", "gaussian"), xlab = NULL, ylab = NULL,
ylim = range(y, prediction$y, na.rm = TRUE), evaluation = 50, lcol="red", ...)
{
xlabel <- if (!missing(x))
deparse(substitute(x))
ylabel <- if (!missing(y))
deparse(substitute(y))
xy <- xy.coords(x, y, xlabel, ylabel)
x <- xy$x
y <- xy$y
xlab <- if (is.null(xlab))
xy$xlab
else xlab
ylab <- if (is.null(ylab))
xy$ylab
else ylab
prediction <- loess.smooth(x, y, span, degree, family, evaluation)
plot(x, y, ylim = ylim, xlab = xlab, ylab = ylab, ...)
lines(prediction, col=lcol) # <<-- Note the edit here
invisible()
}
with(cars, scatter.smooth(speed, dist, col="blue", lcol="green"))