Messy-Plot beim Plotten von Vorhersagen einer Polynom-Regression mit lm () in R

Ich baue ein quadratisches Modell mit lm in R:

y <- data[[1]]
x <- data[[2]]
x2 <- x^2

quadratic.model = lm(y ~ x + x2)

Jetzt möchte ich sowohl die vorhergesagten als auch die tatsächlichen Werte in einem Diagramm anzeigen. Ich habe es versucht:

par(las=1,bty="l")
plot(y~x)
P <- predict(quadratic.model)
lines(x, P)

aber die Leitung kommt ganz schnörkellos hoch. Vielleicht hat es damit zu tun, dass es quadratisch ist? Vielen Dank für jede Hilfe.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage