2

前の投稿と同様に、次のコードを変更したいと思います ( pair() コマンドの R ドキュメントの例から):

## 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" 関数にありますが、それを変更する方法がわかりません。

4

2 に答える 2

1

または、適合した直線をプロットする場合は、joranの答えを変更できます。

my_line <- function(x,y,...){
    points(x,y,...)
    abline(a = lm(y ~ x)$coefficients[1] , b = lm(y ~ x)$coefficients[2] , ...)
}

ただし、実際にペアを使用している場合は、データセットを調査している可能性が高く、その時点で無関係な線形線のフィッティングを保証するため、黄土の方が適切であるように思われます。

于 2014-07-16T17:14:24.193 に答える