简体   繁体   English

corrplot 空白,无意义值的文本

[英]corrplot blank and no text for insignificant values

According to the documentation here it is possible to customize the behavior of insignificant values, to hide them.根据此处的文档,可以自定义无关紧要的值的行为,以隐藏它们。

documentation:文档:

The doc tells us how to do two things I'm interested in:该文档告诉我们如何做我感兴趣的两件事:

  • correlation coefficient ( addCoef.col = "black" )相关系数 ( addCoef.col = "black" )
  • blank insignificant ( sig.level=0.01, insig="blank" )无意义的空白( sig.level=0.01, insig="blank"

Problem:问题:

when using the three above tags (along with others, complete list below) the correlation coefficients also appear for insignificant values.当使用上述三个标签(连同其他标签,下面的完整列表)时,相关系数也会出现在无关紧要的值上。

What I want:我想要的是:

  • have correlation coefficients and colors for all boxes except the insignificant ones除了无关紧要的盒子外,所有盒子都有相关系数和 colors
  • insig boxes must be totally empty签名框必须完全为空

What I do:我所做的:

cr<-colorRampPalette(c("lightblue","white","yellow"))(200)
p <- cor.mtest(dataCor)
corMat=cor(dataCor)

corrplot(corMat, type="upper",method="color",order="original"
            , col=cr
            , tl.col="black"
            , addCoef.col="black",
            , diag=FALSE,number.cex=.7
            , insig="blank"
            , p.mat = p,sig.level=0.01,tl.srt = 45)

results in (extract):结果(提取物): 相关图 The goal is to remove the "-0.01" of prop02 x prop04 and all the zeroes目标是删除 prop02 x prop04 的“-0.01”和所有零

EDIT: I know the props are not in order, in my case it's on purpose (they have different names and are grouped in a relevant way)编辑:我知道道具不按顺序排列,就我而言,这是故意的(它们有不同的名称并以相关方式分组)

UPDATE: I found this thread: corrplot shows insignificant correlation coefficients even when insig = "blank" is set更新:我发现了这个线程: corrplot 显示无关紧要的相关系数,即使设置了 insig = "blank"

It "works" (still a dirty fix) but only for square matrices with diagonals.它“有效”(仍然是一个肮脏的修复),但仅适用于对角线的方阵。 How to make it work for type="upper" and diag=FALSE ?如何使其适用于type="upper"diag=FALSE

One way to tackle the problem is to create a color matrix containing each cell's text color.解决该问题的一种方法是创建一个包含每个单元格文本颜色的颜色矩阵。

The addCoef.col argument can take a matrix. addCoef.col参数可以采用矩阵。 This matrix has to correspond to the final shape given by the other arguments diag and type (in this case: diag=TRUE , type=upper )该矩阵必须对应于其他 arguments diagtype给出的最终形状(在这种情况下: diag=TRUEtype=upper

One way to create this matrix is by creating it from the p-value matrix as follows.创建此矩阵的一种方法是从 p 值矩阵创建它,如下所示。

pval <- 0.01 #threshold
p <- cor.mtest(dataCor) # compute p-values
corMat <- cor(dataCor) # compute correlation values

#create the color matrix from the p-value matrix, select only necessary data
mycol <-ifelse(c(p > pval), "white", "black")[upper.tri(p, diag = FALSE)]

What's happening here:这里发生了什么事:

  • ifelse will return the correponding branch (white or black here) given the logical values in the first argument.如果给定第一个参数中的逻辑值, ifelse将返回相应的分支(此处为白色或黑色)。
  • c(p > pval) creates a logical array with TRUE when the value in the p array is bigger than the p-value threshold.当 p 数组中的值大于 p 值阈值时, c(p > pval)创建一个具有 TRUE 的逻辑数组。 These are the values to mask.这些是要屏蔽的值。 Technically, the condition can be more complex: c(p > pval | abs(corMat)>0.5) .从技术上讲,条件可能更复杂: c(p > pval | abs(corMat)>0.5) In this case there is a condition on both the pvalue and the correlation coefficient.在这种情况下,p值和相关系数都有一个条件。 It can be useful for contrast issues, if the color ramp is too dark for high correlation, white text should be used.它对于对比度问题很有用,如果色带太暗而无法实现高相关性,则应使用白色文本。
  • [upper.tri(p, diag = FALSE)] serves to select only the values we are interested in. upper.tri() returns an array of logical, with TRUE when the value belongs to the desired upper side of the matrix.^ [upper.tri(p, diag = FALSE)]只为 select 提供我们感兴趣的值upper.tri()返回一个逻辑数组,当该值属于所需的矩阵上侧时为 TRUE。^

Presenting values from -100 to 100 is better for readability and understanding.呈现从 -100 到 100 的值更便于阅读和理解。 Using addCoefasPercent=TRUE,cl.lim = c(-100, 100) in the corrplot arguments is arguably better in some cases.在 corrplot arguments 中使用addCoefasPercent=TRUE,cl.lim = c(-100, 100)在某些情况下可以说更好。

更正的配色方案

look at this answer for how to re-order (or keep ordering) ie, what you specify with the order argument (possible values are "AOE", "FPC", "hclust", "alphabet" .查看此答案以了解如何重新排序(或继续排序),即您使用order参数指定的内容(可能的值是"AOE", "FPC", "hclust", "alphabet"

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

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