4

How do I go about adding regression lines to a scatterplot matrix? I have the following script:

NewNEMSIS = read.csv("NewNEMSIS.csv") library(gclus) newmatrix = NewNEMSIS[,2:5] newmatrix.r = abs(cor(newmatrix)) newmatrix.col = dmat.color(newmatrix.r) area = NewNEMSIS$area cpairs(newmatrix[which(area=="A"),c('Response','SceneToPatient','TotalScene','TotalCall')], panel.colors=newmatrix.col, gap=.5, main="Scatterplot Matrix of City A Times", ylim=c(0,60), xlim=c(0,60), na.omit=TRUE, ) 

How can I add splined or sloped regression lines to these scatterplots while keeping them in matrix form? Thanks!

1 Answer 1

5

cpairs is just a colorized version of the base graphics pairs function, and looking at its code you can see that it does accept the regular set of panel functions described and illustrated in ?pairs. This is a reproducible example (which yours is not):

require(gclus) png(); judge.cor <- cor(USJudgeRatings) judge.color <- dmat.color(judge.cor) ?pairs #Review the panel functions ?cpairs cpairs(USJudgeRatings,panel.colors=judge.color,pch=".",gap=.5, upper.panel=panel.smooth) dev.off() 

enter image description here

You should learn to post an example that illustrates the problem. We have no way of knowing what is in that .csv file so showing that you did that operation is useless in understanding what is going on (over an above knowing that the result is a dataframe). It's fine to use examples from the help pages of functions you are asking about.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to overlay the panel.smooth with panel.color. I also did the same thing, but got stumbled with this. (plus one)
If that were the goal you would need to either hack cpairs or make a duplicate of the internal function that cpairs passes to panel and then give it to either upper.panel or lower.panel.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.