如何将回归线添加到散点图矩阵? [英] How do I add regression lines to a scatterplot matrix?

查看:136
本文介绍了如何将回归线添加到散点图矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将回归线添加到散点图矩阵?我有以下脚本:

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!

推荐答案

cpairs 只是基本图形的彩色版本 pairs 函数,通过查看其代码,您可以看到它确实接受了 pairs 。这是一个可重现的示例(您的不是):

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()

您应该学习发布一个说明问题的示例。我们没有办法知道该.csv文件中的内容,因此表明您执行该操作对理解正在发生的事情毫无用处(上面知道结果是一个数据帧)。可以使用所要求功能的帮助页面中的示例。

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.

这篇关于如何将回归线添加到散点图矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆