I want to create a heatmap using the heatmap.2
function from the gplots
package. This is a minimal example.
require(gplots)
# create symmetric matrix
x = matrix(rnorm(100), nrow=10)
diag(x) <- 1
x[upper.tri(x)] <- t(x)[upper.tri(x)]
colnames(x) <- rownames(x) <- letters[1:nrow(x)]
# create side colours
varcols = setNames(rainbow(nrow(x)), rownames(x))
# create heatmap
heatmap.2(x,
symm = TRUE,
trace = "none",
revC=TRUE, # <-- THIS IS THE PROBLEM
ColSideColors = varcols,
RowSideColors = varcols
)
The problem are the sidecolors. x
is a symmetric matrix, thus columns and rows should have the same sidecolors. This is fine as long as revC = FALSE
. However, when I use revC = TRUE
the order of the colors is messed up. Sometimes - in small examples - it helps to reverse the ColSideColors
, but that doesn't always work.
Am I doing anything wrong or is this a gplots
bug?