【发布时间】:2018-03-14 23:33:58
【问题描述】:
我正在尝试用回归线绘制函数而不是低线替换 pairs() 中的参数 panel 的 panel.smooth,但没有成功。
我尝试创建函数 reg 并将其放置在参数 panel 中,但这不起作用?有什么办法吗?
reg <- function(x, y) abline(lm(y~x)) # made to draw regression line instead of lowess line
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)
text(0.5, 0.5, txt, cex = 1.1, font = 4)
}
#EXAMPLE OF USE:
pairs(USJudgeRatings[1:5], panel = panel.smooth, # replace HERE for panel.smooth #
cex = 1.5, pch = 19, col = adjustcolor(4, .4), cex.labels = 2, font.labels = 2, lower.panel = panel.cor)
【问题讨论】: