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!

  • $\begingroup$ 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 $\endgroup$
    – user25658
    Sep 18, 2013 at 1:57
  • $\begingroup$ 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. $\endgroup$
    – ttnphns
    Sep 18, 2013 at 8:07
  • 2
    $\begingroup$ @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$. $\endgroup$
    – ttnphns
    Sep 18, 2013 at 8:23

1 Answer 1


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

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

     ylab="Response Variable",xlab="Independent Variable")

#Adding a legend if desired
legend("topright",c("Group 1","Group 2"),pch=19,col=c("deepskyblue","red"),bg="white")

Which then generates the following plot: enter image description here

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

  • $\begingroup$ 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. $\endgroup$
    – DPY
    Sep 18, 2013 at 2:01
  • $\begingroup$ I am not sure what you mean corrected for a covariate but you are welcome. $\endgroup$
    – user25658
    Sep 18, 2013 at 2:11
  • $\begingroup$ @DPY would you like me to edit my answer to reflect what ttnphns's comment suggested? $\endgroup$
    – user25658
    Sep 18, 2013 at 17:57

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.