corrplot icon indicating copy to clipboard operation
corrplot copied to clipboard

specifying the color range

Open imilenkovic opened this issue 3 years ago • 1 comments

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 avatar Aug 10 '22 15:08 imilenkovic

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

imilenkovic avatar Aug 10 '22 15:08 imilenkovic

You can set col.lim.

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

taiyun avatar Aug 18 '22 05:08 taiyun

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!

imilenkovic avatar Aug 26 '22 16:08 imilenkovic

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

taiyun avatar Aug 29 '22 03:08 taiyun

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!

imilenkovic avatar Aug 29 '22 08:08 imilenkovic

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

taiyun avatar Aug 31 '22 04:08 taiyun