When building a line, all points are connected in the order in which they were received. It looks like you want to sort the values hpbefore connecting the dots
res <- data.frame(cbind(mpg, fitted(fit), hp))
res <- res[order(hp), ]
with(res, plot(hp, mpg))
with(res, lines(hp, V2))
To obtain

, , , hp, . , ,
php <- seq(min(hp), max(hp), length.out=100)
p <- predict(fit, newdata=data.frame(hp=php))
plot(hp, mpg)
lines(php, p)
