-
Notifications
You must be signed in to change notification settings - Fork 41
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
aheatmap() color and breaks #12
Comments
Thanks for reporting this. This is sort of already fixed in the development version (see below on how to install). # force using 3 bins
aheatmap(mat2, color = brewer.pal(n = 3, name = 'YlOrBr'), breaks = 3L)
# or (as you said) slightly different: use 3 bins across full YlOrBr palette
aheatmap(mat2, color = 'YlOrBr:3') Note that With respect to using black for NA and 0, this should do the trick, the idea being that you define a black color bin that gathers only zero values: mat2 = matrix(runif(15), nrow=5)
mat2[1:3] <- NA
mat2[6:8] <- 0
nbins <- 3
aheatmap(mat2, col = c('black', brewer.pal(n = nbins, name = 'YlOrBr')), breaks = c(0, seq(min(mat2, na.rm = TRUE) + .Machine$double.eps, max(mat2, na.rm = TRUE), length.out = nbins+1)), Colv = NA, Rowv = NA)
# for NA values as well
mat2[is.na(mat2)] <- 0
aheatmap(mat2, col = c('black', brewer.pal(n = nbins, name = 'YlOrBr')), breaks = c(0, seq(min(mat2, na.rm = TRUE) + .Machine$double.eps, max(mat2, na.rm = TRUE), length.out = nbins+1)), Colv = NA, Rowv = NA) Installing from github without Latex:install_github("renozao/NMF", quick = TRUE)
# or development version
install_github("renozao/NMF", ref = 'devel', quick = TRUE) |
I added argument mat2 = matrix(runif(15), nrow=5)
mat2[6:8] <- 0
mat2[1:3] <- NA
# No color
aheatmap(mat2, Colv = NA, Rowv = NA)
# NA values only
aheatmap(mat2, na.color = 'black', Colv = NA, Rowv = NA)
# zeros as NA
aheatmap(mat2, na.color = list('black', 0), Colv = NA, Rowv = NA)
# range of values as NA
aheatmap(mat2, na.color = list('black', c(0, .5)), Colv = NA, Rowv = NA) It is still in development stage though, because the scale is not yet adapted to show the na.color. |
@slowkow is the issue solved and can be closed? |
Yes, thank you for the code examples! That was very helpful. I appreciate it. |
In the function
aheatmap()
, thecolor
andbreaks
parameters areimplemented incorrectly.
My goal is to use the color black, for example, for NA (or 0) values and
palette colors for all other values. Currently, that seems to be impossible
because the
color
andbreaks
parameters do not work correctly.This code works as expected:
This code produces a heatmap with 50 colors, despite my effort to get
3 colors:
This code also fails because only the first 3 of the 50 colors are used:
(Some of) the code with the incorrect implementation is in
colorcode.R
:https://github.com/renozao/NMF/blob/master/R/colorcode.R#L213
Notice the line with
if( is_NA(n) ) n <- 50
. This ensures that theexpression
n <- length(x)
will never be executed. This explainswhy I see 50 colors instead of the number I want.
The text was updated successfully, but these errors were encountered: