taiyun / corrplot

A visual exploratory tool on correlation matrix
https://github.com/taiyun/corrplot
Other
316 stars 86 forks source link

Midpoint color is not white #228

Closed bixiou closed 2 years ago

bixiou commented 2 years ago

Hello,

considering the following code, I would wish that the cell "50" is white and the higher cells blue, but all cells are red (which should be limited to values lower than the middle 50). What am I doing wrong?

corrplot(matrix(c(0.8, 0.5, 0.6, 0.7), ncol=2), method='color', col.lim = c(0, 1), addCoef.col = 'black', addCoefasPercent = T, type="full", is.corr = F)

Rplot01

bixiou commented 2 years ago

I have tested the same code on another computer (where corrplot's version is 0.84 instead of 0.90), and the result is even weirder. The example above works well... but when I change the values in the matrix, similar bugs reappear. See below. Same code as above (produces the expected result: Rplot!02

This one also works well: Rplot

But this one bugs: Rplot01

taiyun commented 2 years ago

Please read the manual.

col.lim

The limits (x1, x2) interval for assigning color by col. If NULL, col.lim will be c(-1, 1) when is.corr is TRUE, . col.lim will be c(min(corr), max(corr)) when is.corr is FALSE

NOTICE: if you set col.lim when is.corr is TRUE, the assigning color method is still distributed uniformly in [-1, 1], it only affect the display on color-legend.

is.corr

Logical, whether the input matrix is a correlation matrix or not. We can visualize the non-correlation matrix by setting is.corr = FALSE.

bixiou commented 2 years ago

I had read the manual, and corrplot does not behave like it should. Notice that in my examples, is.corr is set to FALSE. Hence, col.lim = c(0, 1) should be used. But it is not. Also, notice that in my example, the colors limit are not even set to c(min(corr), max(corr)) (in which case we would have a dark red and a dark blue cell in each example). So there really is a bug. Can you provide a patch?

taiyun commented 2 years ago

@bixiou Can you try the latest version corrplot on github?

Here are some examples that works well.

corrplot(matrix(c(0.8, 0.5, 0.6, 0.7), ncol=2), method='color', 
         col.lim = c(0, 1), addCoef.col = 'black', addCoefasPercent = T, 
         type="full", is.corr = F)

corrplot(matrix(c(0.2, 0.4, 0.6, 0.8), ncol=2), method='color', 
         col.lim = c(0, 1), addCoef.col = 'black', addCoefasPercent = T, 
         type="full", is.corr = F)

corrplot(matrix(c(1:9)/10, ncol=3), method='color', 
         col.lim = c(0, 1), addCoef.col = 'black', addCoefasPercent = T, 
         type="full", col = COL2('RdYlBu'), is.corr = F)

corrplot(matrix(c(1:9)/10, ncol=3), method='color', 
         col.lim = c(0, 1), addCoef.col = 'black', addCoefasPercent = T, 
         type="full",  is.corr = F)
bixiou commented 2 years ago

The install failed, but I copy/pasted the code of corrplot() from github and it works. Thank you!

FYI, here is the install error: E> * creating vignettes ... ERROR E> --- re-building 'corrplot-intro.Rmd' using rmarkdown E> Error: processing vignette 'corrplot-intro.Rmd' failed with diagnostics: E> no package named 'prettydoc' can be found E> --- failed re-building 'corrplot-intro.Rmd' E> E> RESUME : le traitement du fichier suivant a échoué : E> 'corrplot-intro.Rmd' E> E> Erreur : Vignette re-building failed.

taiyun commented 2 years ago

You should install prettydoc package first.

Thanks again.

taiyun commented 2 years ago

@bixiou I updated corrplot to v0.92 on Github. You can test this bug further if you have time.

bixiou commented 2 years ago

It works well, thank you!

taiyun commented 2 years ago

OK. Thanks.