Using R and ggplot, I would like to plot my output variable with one of my predictor variables adjusted for the other variables in the model. (I'm asking this question here, because I don't actually know if this is statistically a good idea! Please let me know if not!)

A model using dtcars data (nabbed from here).

mod <- lm(mpg ~ drat + wt, mtcars)

I would like to produce this graph, but with wt adjusted for drat.

ggplot(mtcars, aes(wt, mpg)) + geom_point()

GGplot example

Is there a way I can get the adjusted values for wt out of mod? Does this even make sense to do? Or should I just settle with presenting univariate graphs and coefficients in tables?


2 Answers 2


One of many ways:

dd <- datadist(mtcars); options(datadist='dd')
mod <- ols(mpg ~ drat + wt, mtcars)
plot(Predict(mod, wt))  # show partial effect of wt
plot(Predict(mod))      # show partial effects of all predictors
# 0.95 pointwise confidence intervals are included
# If predictors are modeled nonlinearly with regression splines,
# only the model formula need be changed

In stats we don't actually adjust values, we adjust summaries or outputs. In this case, you wouldn't adjust the values of the predictor variable, but you would adjust the coefficient for this variable (the difference between the coefficient in a univariate model and a multivariate). Similarly, we adjust the odds ratios, but not the data that goes into calculating the odds ratio.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.