繁体   English   中英

corrplot:如何定位系数数字下方的重要符号 (**)

[英]corrplot: how to locate the significant symbol (**) below the coefficient numbers

相关性 plot 具有重要的符号和数字重叠。 有谁知道如何找到数字下方的重要符号?

在此处输入图像描述

 cor <- Hmisc::rcorr(mtcars %>% as.matrix())
 corrplot::corrplot(cor$r, method="color", tl.cex = 1, tl.col = "black", number.cex = 0.8,
               p.mat = cor$P, sig.level = c(.001, .01, .05), insig = 'label_sig', 
               pch = 10, pch.cex = 1, pch.col = "white", type = "lower", tl.srt = 45, 
               addCoef.col = "black", addgrid.col = "white", cl.pos = "n",
               fn_left=135, fn_up = 20,
               cl.lim=c(-1, 1))

ggplot2可以提供更大的灵活性

library(ggplot2)

nm = rownames(cor$r)
m = t(combn(nm, 2))
d = cbind(data.frame(m), R = cor$r[m], P = cor$P[m])
d$label = round(d$R, 2)
d$label[d$P < 0.001] = paste0(d$label[d$P < 0.001], "\n**")
d$X1 = factor(d$X1, nm)
d$X2 = factor(d$X2, rev(nm))

graphics.off()
ggplot(d, aes(X1, X2, fill = R, label = label)) +
    geom_tile(color = "white") +
    scale_fill_viridis_c() +
    geom_text(color = ifelse(d$R > 0.35, "black", "white")) +
    theme_bw() +
    coord_equal()

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM