问题
I'm visualizing a data set with the heatmap.2
function from the gplots
package in R. Basically I'm performing a hierarchical clustering analysis on the original data, while forcing the heatmap to display a limited version of the data (between -3 and +3) to limit the effect of outliers on the appearance of the heatmap, while still retaining the original clustering. When I use the full data set (fullmousedatamat
), it works just fine. However, when I use a partial data set (partialmousedatamat
), and want to plot it using the same key as the full data set, a couple colors are dropped out of the key and I can't figure out why.
Here is a gist containing the relevant data sets and analyses:
https://gist.github.com/jeffbruce/7412f567ac57fe1721a3
Notice how the 4th color on either side of the centre white color are dropped out. This feels like a bug to me maybe. I get the following warning message which I'm not sure how to interpret:
Warning message:
In image.default(z = matrix(z, ncol = 1), col = col, breaks = tmpbreaks, :
unsorted 'breaks' will be sorted before use
Thanks for your help!
回答1:
I came across the same issue and I had to go through the code for heatmap.2
to figure it out.
It turns out that symkey=T
, which is the default, adds the extreme values of the data at both ends of breaks
, rendering it un-sorted:
tmpbreaks <- breaks
if (symkey) {
max.raw <- max(abs(c(x, breaks)), na.rm = TRUE)
min.raw <- -max.raw
tmpbreaks[1] <- -max(abs(x), na.rm = TRUE)
tmpbreaks[length(tmpbreaks)] <- max(abs(x), na.rm = TRUE)
}
Therefore, the simple way to solve this is adding symkey=F
if you are providing your own breaks.
来源:https://stackoverflow.com/questions/30675625/r-gplots-heatmap-2-key-is-unstable-using-breaks-parameter-warning-unsorted