在R中使用Pairs()命令向相关图添加标识线 [英] Adding line of identity to correlation plots using pairs() command in R

查看:183
本文介绍了在R中使用Pairs()命令向相关图添加标识线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于上一篇文章,想要修改以下代码(来自R文档中的groups()命令)中的示例:

Similar to a prevous post, I'd like to modify the following code (from example in the R documentation for pairs() command):

## put (absolute) correlations on the upper panels,
## with size proportional to the correlations.
panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...)
{
    usr <- par("usr"); on.exit(par(usr))
    par(usr = c(0, 1, 0, 1))
    r <- abs(cor(x, y))
    txt <- format(c(r, 0.123456789), digits = digits)[1]
    txt <- paste0(prefix, txt)
    if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
    text(0.5, 0.5, txt, cex = cex.cor * r)
}
pairs(USJudgeRatings, lower.panel = panel.smooth, upper.panel = panel.cor)

我希望每个情节都具有一条身份线,而不是一条黄土线。秘密在于$ panel.smooth函数,但是我不知道如何修改它。

Instead of a loess line, I want a line of identity for each plot. The secret lies in the $"panel.smooth" function, but I don't know how to modify it.

推荐答案

我认为您的意思是这样的:

I think you just mean something like this:

my_line <- function(x,y,...){
    points(x,y,...)
    abline(a = 0,b = 1,...)
}
pairs(USJudgeRatings, lower.panel = my_line, upper.panel = panel.cor)

这篇关于在R中使用Pairs()命令向相关图添加标识线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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