# Partial correlation plot, split by groups SPSS

Is it possible to illustrate partial correlation scatter plots for 2 subgroups on the same graph?

e.g. I want to make scatter plots of data controlled for age, differentiated by males or females.

I've tried doing partial regression plots generated by linear regression analysis, but I can't split it by groups.

Options to do it in excel or R would be fine too. Thanks!

• I am not sure what exact plot you want (from reading your question I believe you are looking for a scatterplot of the data colored by groups) but hopefully my answer below gets at the heart of your question about plotting in R – user25658 Sep 18 '13 at 1:57
• It is unclear in the end is your question related to SPSS. In SPSS Linear Regression procedure you can request partial correlation scatterplots. But they won't be group-coloured. Anyway, since you know what such a plot is, you can easily plot it yourself in any colouration you fancy - after you saved the appropriate two variables of residuals from the regression analysis procedure. – ttnphns Sep 18 '13 at 8:07
• @BabakP, I understood it such that DPY wants a scatterplot between the residuals left by regressing $Y$ by all the variables except $X$ and the residuals left by regressing $X$ by all those variables except $Y$. This what is known as partial correlation scatterplot between $X$ and $Y$. – ttnphns Sep 18 '13 at 8:23

Here is some code for how you could do it in R:

#Psuedo Data
group1 = rnorm(100)
group2 = rnorm(100)
response = rnorm(100)

#Plotting
plot(group1,response,xlim=c(min(group1,group2),max(group1,group2)),pch=21,bg="deepskyblue",
ylab="Response Variable",xlab="Independent Variable")
points(group2,response,pch=21,bg="red")

legend("topright",c("Group 1","Group 2"),pch=19,col=c("deepskyblue","red"),bg="white")


Which then generates the following plot:

You could obviously add your own aesthetic touched but this should give you the general idea.

• thanks for that. I meant making a scatter plot for data which has been corrected by a covariate, and also splitting it into groups as you've suggested. – DPY Sep 18 '13 at 2:01
• I am not sure what you mean corrected for a covariate but you are welcome. – user25658 Sep 18 '13 at 2:11
• @DPY would you like me to edit my answer to reflect what ttnphns's comment suggested? – user25658 Sep 18 '13 at 17:57