[R] Newbie question: plotting regression models

Andy Bunn abunn at whrc.org
Wed Nov 3 16:56:19 CET 2004


Welcome to R.

You can start by looking at the predict function for the regression model you are using (e.g., ?predict.lm if you are using a linear model).

Then do something like so:

data(cars)
cars.lm <- lm(dist ~ speed, cars)
dist.pred <- predict(cars.lm)
plot(cars$speed, cars$dist, ylim = c(-2, 120))
lines(cars$speed, dist.pred, col = "red", lwd = 2)


HTH, Andy




More information about the R-help mailing list