JIC1e14
JIC1e14

Reputation: 21

Adding Regression Lines to Multiple Scatter Plots

Had a look around and couldn't find an answer to my question, so finally stopped lurking. I've been creating multiple scatter plots comparing each column to the others as shown here

I used the script

attach(`File`)
plot(`Files`[,c(2,3,4,5,6,7,8)])

However I can't seem to correctly input the command to annotate the regression line and r2 value onto the graphs.

Upvotes: 2

Views: 3834

Answers (1)

TPArrow
TPArrow

Reputation: 1584

here is the solution. Assume Z is your design matrix.

z=matrix(rnorm(500),ncol=5)

pairs( z, panel=function(x,y){
  points(x,y)
  abline(lm(y~x), col='red')
  text(0,1.5,labels = paste('R2=',round((cor(x,y))^2,2)) ,col='red' )
})

and result should be like this enter image description here

Upvotes: 4

Related Questions