visreg
An R package for the visualization of regression models

As noted in getting started, the default behavior of visreg when constructing a conditional plot is to fill in the other variables with either the median (for continuous variables) or the most common category (for categorical variables). This can be modified using the cond argument, which offers more explicit control over what to condition on. Note that this has no bearing on contrast plots (at least, in the absence of interactions), which do not depend on the other terms in the model.

The cond argument must be provided as a named list. Each element of that list specifies the value for one of the terms in the model; any elements left unspecified are filled in with the median/most common category. For example, let’s construct the a plot of wind vs. ozone, but condition on three different values for temperature: (1) a cold temperature of 50 degrees (2) the default median temperature of 79 degrees and (3) a hot temperature of 100 degrees.

fit <- lm(Ozone ~ Solar.R + Wind + Temp, data=airquality)
par(mfrow=c(1,3))
visreg(fit, "Wind", cond=list(Temp=50))
visreg(fit, "Wind")
visreg(fit, "Wind", cond=list(Temp=100))

plot of chunk wind_temp

A few observations/remarks:

Finally, recall that this model had three explanatory variables; in the above example, visreg calculated the conditional response by filling in solar radiation with its median value, as it was not specified otherwise in the cond argument.