有没有办法在 GGally 中使用 WRS2 添加稳健的相关性和显着性值/星星:ggpairs 图?

问题描述 投票:0回答:1

ggpairs
图仅使用基本
cor
方法计算相关性。我们如何向绘图提供
pbcor
wincor
值/p 值(来自
WRS2
包)?

r ggally
1个回答
0
投票

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

Example of a ggpairs matrix with pbcor

© www.soinside.com 2019 - 2024. All rights reserved.