-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjusting cl.lim does not change range of colors #122
Comments
@taiyun @caijun @vsimko We have been using We now came across datasets with a very narrow range of correlations, for example |
|
@taiyun |
@taiyun Sorry. We still have problems. Here an example.
The range |
fixed in pull request #127 |
Thank you @vsimko :) |
cl<- c("#56A36C","#5E8579","#77C34F","#2E68AA","#7E884F","#7C8489","#4fB3A4","#F5B977") |
Hi, I still have this problem. How can I fix this? The version is
|
Sorry, it seems only accept two color if cl.lim is positive. 2019-01-11 08:43:02>"Ji Huang" 写道:
Hi, I still have this problem. How can I fix this?
The version is corrplot_0.85.
Thank you!
@taiyun Sorry. We still have problems. Here an example.
d <- 0.2*abs(cor(mtcars))+0.6
colmat <- colorRampPalette(c("red", "white", "blue"))
corrplot(d, cl.lim=c(min(d),max(d)), col = colmat(200), is.corr=FALSE)
The range (0.61, 0.8) is correct, but the colour palette is white-blue and not the expected red-white-blue.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Problem persists with corrplot 0.84 in R 3.2.2. |
Hello there, @lars20070 , did you find a workaround, or alternatives? Would be great to hear about it! |
Same question as these guys.The range is correct, but the colour palette is white-blue and not the expected red-white-blue. @taiyun |
Thanks! |
Hi! I am still having this issue (version 0.84 in R 3.6.2). It seems that no matter what values are in the matrix, if they are positive it will use the first half of colors. If the matrix has negative values, it will use the second half. So cl.lim is not distributing the color palette to the min and max values of the matrix, the function is assigning them directly to negative and positive values. Does it have to do with the function
Or maybe when the corr matrix is being transformed somehow here when is.corr = F?
Examples of the issue:
That will give only positive (blue to white) colors. However, if the matrix is negative:
It will show only white to red colors. cl.lim option does not work when is.corr = F, it always gives and error, even when giving values in range of the matrix:
|
Hi! Actually, I finally used the geom_tile function from the ggplot2 package instead. It is more friendly to adjusting the correlation coefficient interval.
2020-04-20 18:18:49"joseale2310" <[email protected]>写道:
Hi! I am still having this issue (version 0.84 in R 3.6.2). It seems that no matter what values are in the matrix, if they are positive it will use the first half of colors. If the matrix has negative values, it will use the second half. So cl.lim is not distributing the color palette to the min and max values of the matrix, the function is assigning them directly to negative and positive values. Does it have to do with the function
assign.color <- function(dat = DAT, color = col) {
newcorr <- (dat + 1)/2
newcorr[newcorr <= 0] <- 0
newcorr[newcorr >= 1] <- 1 - 1e-16
color[floor(newcorr * length(color)) + 1]
}
Or maybe when the corr matrix is being transformed somehow here when is.corr = F?
if (!is.corr) {
c_max <- max(corr, na.rm = TRUE)
c_min <- min(corr, na.rm = TRUE)
if (c_max <= 0) {
intercept <- -cl.lim[2]
zoom <- 1/(diff(cl.lim))
}
else if (c_min >= 0) {
intercept <- -cl.lim[1]
zoom <- 1/(diff(cl.lim))
}
else {
stopifnot(c_max * c_min < 0)
stopifnot(c_min < 0 && c_max > 0)
intercept <- 0
zoom <- 1/max(abs(cl.lim))
}
if (zoom == Inf) {
stopifnot(cl.lim[1] == 0 && cl.lim[2] == 0)
zoom <- 0
}
corr <- (intercept + corr) * zoom
}
Examples of the issue:
col1 <- colorRampPalette(c("red","white", "blue"))
ran <- round(matrix(runif(225, 100,200), 15))
corrplot(ran, is.corr = FALSE, method = "square", col = col1(200))
That will give only positive (blue to white) colors. However, if the matrix is negative:
col1 <- colorRampPalette(c("red","white", "blue"))
ran <- round(matrix(runif(225, -200,-100), 15))
corrplot(ran, is.corr = FALSE, method = "square", col = col1(200))
It will show only white to red colors. cl.lim option does not work when is.corr = F, it always gives and error, even when giving values in range of the matrix:
col1 <- colorRampPalette(c("red","white", "blue"))
ran <- round(matrix(runif(225, 100,200), 15))
corrplot(ran, is.corr = FALSE, method = "square", col = col1(200), cl.lim = c(125,175))
Error in corrplot(ran, is.corr = FALSE, method = "square", col = col1(200), :
color limits should cover matrix
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Solved now. Please try the latest version on github. |
cl.lim is now col.lim. Correct? |
It does not seem solved. I still have this issue happening. The color was scaled based on [-1,1], rather than the col.lim even setting is.corr FALSE.
A quick test, seems when the corr has values < 0, it's not working. If all values >=0, it worked fine. And if I set parameter transKeepSign = F, it worked. |
I have a work-around to this. One needs to put the (color legend) value limits in the corrplot high enough, preferably above -1 or 1 in the positive side and make sure that the negative value's limit is the same (but abs) in magnitude in the positive side. Something like: #So these are the key lines, so as not to blur values between -1 and 0: if (hepsa-heps >=0 ) {resulta1[resulta1 >= heps2] = hepsa; resulta1[resulta1 <= -heps3] = -hepsa; heps=hepsa} else #Check if you have just positive or negative values or both: #Now just to plot you need some values for corrplot, including corr=F if you do not have values exactly between -1 and 1: corrplot(as.matrix(resulta1), type = type, order = order,method=method, p.mat=as.matrix(p.mat.a1), tl.col = "black", dev.off() I hope this helped. |
Hello,
when the
cl.lim
parameter is restricted to a smaller range e.g.(0, 1)
one would expectthat for a given color palette, e.g.
col3 <- colorRampPalette(c("red", "white", "blue"))
all colors are still used to visualize points in the new range.
However, the default range
(-1, 1)
is still used, which leads people to prepend unused colors in order to visualize things in their desired color range, as in:https://stackoverflow.com/a/30744267/9434598
https://stackoverflow.com/a/38876691/9434598
This is problematic if e.g. all correlation values are high, because one needs to prepend a large amount of colors in this way to see differences in the correlations.
I have ideas for a fix and some candidate code ready, but would first like to get your opinion on whether this is an issue you would like to address or whether I am overlooking something.
I hope we can collaborate on this and find a good solution for everyone.
Best,
MFreidank
The text was updated successfully, but these errors were encountered: