taiyun / corrplot

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

specifying the color range #255

Closed imilenkovic closed 2 years ago

imilenkovic commented 2 years ago

Hello,

I was wondering if it would be possible to specify the range in which a color gradient will be applied? For example: image

in this plot the range is from 1 to -1, but I would like to only have it eg. from 1 to -0.15, so that the values around 0 are bright yellow and values around 1 are brown?

Thank you.

imilenkovic commented 2 years ago

This was the code:

corrplot(cor(merged2), # Correlation matrix method = "shade", # Correlation plot method type = "full", # Correlation plot style (also "upper" and "lower") diag = TRUE, # If TRUE (default), adds the diagonal tl.col = "black", # Labels color bg = "white", # Background color title = "", # Main title

col.lim = c(0.9,1),

     is.corr = FALSE,
     COL1(sequential = c("YlOrBr")))        # Color palette
taiyun commented 2 years ago

You can set col.lim.

Examples: https://taiyun.github.io/corrplot/

imilenkovic commented 2 years ago

Hello,

When I set col.lim, the colour distribution stays the same.

corrplot(cor(merged2),        # Correlation matrix
         method = "shade", # Correlation plot method
         type = "full",    # Correlation plot style (also "upper" and "lower")
         diag = TRUE,      # If TRUE (default), adds the diagonal
         tl.col = "black", # Labels color
         bg = "white",     # Background color
         title = "",       # Main title
         col.lim = c(-0.15,1),
         is.corr = FALSE,
         COL1(sequential = c("YlOrBr")))        # Color palette

image

When changing is.corr to TRUE, it's still the same:

corrplot(cor(merged2),        # Correlation matrix
         method = "shade", # Correlation plot method
         type = "full",    # Correlation plot style (also "upper" and "lower")
         diag = TRUE,      # If TRUE (default), adds the diagonal
         tl.col = "black", # Labels color
         bg = "white",     # Background color
         title = "",       # Main title
         col.lim = c(-0.15,1),
         is.corr = TRUE,
         COL1(sequential = c("YlOrBr")))        # Color palette

image

I assume that I would have to use diverging colours here, but the same colour palette doesn't exist with diverging colours. I already made many other plots with this colour scheme so I would prefer to stick to the same colours if at all possible. Thanks!

taiyun commented 2 years ago

Please update the new version v0.93 from Github. And set ignoreSign = TRUE.

imilenkovic commented 2 years ago

Hello,

I updated the package and ran the following:

corrplot(cor(merged2),        # Correlation matrix
         ignoreSign = TRUE,
         method = "shade", # Correlation plot method
         type = "full",    # Correlation plot style (also "upper" and "lower")
         diag = TRUE,      # If TRUE (default), adds the diagonal
         tl.col = "black", # Labels color
         bg = "white",     # Background color
         title = "",       # Main title
         col.lim = c(-0.2,1),
         is.corr = FALSE,
         COL1(sequential = c("YlOrBr")))   

and got the following warning

Warning message: In corrplot(cor(merged2), ignoreSign = TRUE, method = "shade", type = "full", : col.lim interval not suitable to the matrix

The plot now looks like this:

image

So all good, thanks a lot!

taiyun commented 2 years ago

Please update the new version v0.93 from Github. And set ignoreSign = TRUE.

ignoreSign = TRUE is very easy to misunderstood.

I rename it, please set transKeepSign = FALSE after updating. Like:

merged2 = matrix(runif(100,-0.18,0.99),10,10)
corrplot(merged2,          # Correlation matrix
         method = "color", # Correlation plot method
         type = "full",    # Correlation plot style (also "upper" and "lower")
         diag = TRUE,      # If TRUE (default), adds the diagonal
         tl.col = "black", # Labels color
         bg = "white",     # Background color
         title = "",       # Main title
         col.lim = c(-0.2,1),
         cl.length = 13,
         is.corr = FALSE,
         transKeepSign = FALSE,
         COL1(sequential = c("YlOrBr")))        # Color palette

Rplot