我目前正在使用R 中的corrplot()包corrplot,并且偶然发现了两个问题。为简单起见,我将使用与 corrplot 的帮助/介绍页面相同的符号。
我想在所有单元格中记下我的 p 值或测试的显着性(或两者!),而不仅仅是不显着的单元格。
我只想在上三角形中刻上这些铭文。
首先要解决 2) 问题,我已经能够使用它,但感觉有点 hacky:
corrplot(M, type="upper", p.mat = res1[[1]], insig="p-value", tl.pos="n")
corrplot(M, type="lower", add=T, tl.pos="d", cl.pos="n"))
Run Code Online (Sandbox Code Playgroud)
然而我还没能弄清楚第一点。任何建议都会有帮助的!
快速方法是添加sig.level=0到第一个图,以便显示所有 p 值(实际上,由于数值精度,某些 p 值将恰好为零,因此您可能需要将其设置为sig.level=-0.1,例如)
require(corrplot)
# Data
M <- mtcars[3:7]
pval <- psych::corr.test(M, adjust="none")$p
# Corrplot
corrplot(cor(M), type="upper", p.mat=pval, insig="p-value",
tl.pos="n", sig.level=0)
corrplot(cor(M), type="lower", add=T, tl.pos="d", cl.pos="n")
Run Code Online (Sandbox Code Playgroud)
这给出了

但是,如果您想向 p 值添加更多详细信息,后格式化绘图并使用调用添加它们可能会更text容易
# Plot
corrplot(cor(M), type="upper", tl.pos="n")
# Get positions & plot formatted p-values
pos <- expand.grid(1:ncol(pval), ncol(pval):1)
text(pos, p_format(pval))
# lower tri
corrplot(cor(M), type="lower", add=T, tl.pos="d", cl.pos="n")
Run Code Online (Sandbox Code Playgroud)
给予

格式化功能
p_format <- function(x, ndp=3)
{
out <- format(round(as.numeric(x),ndp),ns=ndp,scientific=F,just="none")
ifelse(out=="0.000","<0.0001", out)
}
Run Code Online (Sandbox Code Playgroud)
我的观点(fwiw)是,这给情节添加了太多信息