ggpairs
允许您为矩阵的不同方面提供自定义函数(作为 upper、lower 和 diag 的参数)。还有一个
ggally_statistic
函数允许您将其他函数/测试的结果打印到这些方面。通过使用正确的参数包装此函数(使用 GGally 包提供的包装机制),我们可以使用 require 相关性度量轻松创建自定义函数。
library(GGally)
d <- data.frame(A=rnorm(100),
B=rnorm(100),
C=rnorm(100))
mcor <- wrap(ggally_statistic,
title="pbcor", # name of the metric to be displayed
text_fn = function(x, y) {
corObj <- WRS2::pbcor(x, y) # use the desired function here or add arguments
cor_txt <- formatC(corObj$cor, digits = 3, format = "f")
cor_txt <- stringr::str_c(cor_txt, signif_stars(corObj$p.value))
cor_txt
})
ggpairs(d, upper = list(continuous = mcor))