taiyun / corrplot

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

Fixing colour scale for diagonal elements. #125

Closed protivinsky closed 6 years ago

protivinsky commented 6 years ago

ifelse function returns vector of length equal to the length of condition. Default is "diag = TRUE", which has length one, hence the diagonal is effectively replaced by its first element when constructing the colour scale via corr_tmp. This PR fixes it so the whole diagonal is preserved.

The following code illustrates the problem - compare the colour scales of these plots, the second one is correct, but the first one is not:

library(corrplot)
M <- matrix(data = c(2, 1, 1, 1, -2, 1, 1, 1, 4), nrow = 3)
corrplot(M, is.corr = F)

M <- matrix(data = c(2, 1, 1, -2, 1, 1, 4, 1, 1), nrow = 3)
corrplot(M, is.corr = F)