# How can I create a scatterplot in R using the plot function to control for covariates?

I would like to know if it is possible to create a scatterplot while controlling for covariates, such as in partial correlation. I am using R software and my code is below for the basic scatterplot.

I am not interested in multiple lines of best fit or multiple scatters per graph. I am also not interested in creating a lattice of scatterplots with all of the variables.

I can't seem to find any code that will allow me to parse the effect of the covariates from my x-y scatterplot. All three covariates are continuous. Any ideas would be helpful.

plot(pmc$$reject, pmcp$$LPA, main="r(Parenting, Left Amygdala)",
xlab="Parenting Age 2", ylab="Amygdala Reactivity Age 15", pch=19)
abline(lm(pmc$$reject ~ pmcp$$LPA), col="red") # regression line (y~x)

• One way would be to fit a regression model using all covariates, and then predict y values for x using some fixed value for all the covariates (either the mean, or the most common value for factors). This can be done with predict().
– MrFlick
Jun 30 '14 at 19:04
• Please consider adding a minimal example dataset for pmcp. Jun 30 '14 at 19:16

As said in comments, one way would be to fit a regression model, and then plot predictions with some covariates hold at fixed values, and the one used on the x-axis with its observed values. The Rpackage effects (on CRAN) can be useful.
Another idea, especially with three variables (but combined with the above ideas could be used with more) is conditioning plots, made in R with the function coplot. On this site some examples can be found here, used for investigating interactions, another example with R dataset swiss, and used for investigating conditional correlations, or search this site.