lrthistlethwaite
lrthistlethwaite

Reputation: 536

heatmap.2 colors really wonky

Does anyone know why my heatmap.2 result has weird colors - the turquoise doesn't belong in my red/black/green palette? It appears the turquoise refers to information based on sample clustering (the row dendrogram which I "FALSE"-ed out), and not based on feature clustering. What's up with this?

I am using gplots, RBrewerColor and heatmap.2() method.

Code:

temp <- t(iris[,1:4])
sampleLabels.c <- as.character(iris[,5])
sampleLabels.c[sampleLabels.c=="setosa"] <- "red"
sampleLabels.c[sampleLabels.c=="versicolor"] <- "orange"
sampleLabels.c[sampleLabels.c=="virginica"] <- "green"

# Sort on max difference
t.min <-apply(temp, 1, min)
t.max <- apply(temp, 1, max)
temp <- temp[order(t.max-t.min, decreasing=TRUE),]
# cluster on correlation
hc <- hclust(as.dist(1 - cor(temp)), method="average")
png("iris.png", 1000, 1000)
par(mar=c(1,1,1,1))
heatmap.2(as.matrix(temp),
      Rowv=FALSE,
      Colv=as.dendrogram(hc),
      dendrogram="column",
      col=greenred(10),
      labRow="", labCol="", key=TRUE,
      ColSideColors=sampleLabels.c)
legend("left",
   legend=c("Setosa", "Versicolor", "Virginica"),
   col=c("red", "orange", "green"),
   lty=1, lwd=2)
dev.off()

Here is the image that generates from the code (above).

enter image description here Thanks for any insights!

Upvotes: 3

Views: 897

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226162

Searching for "cyan" in ?heatmap.2 gives:

trace=c("column","row","both","none"), tracecol="cyan" ... ...

trace: character string indicating whether a solid "trace" line should be drawn across 'row's or down 'column's, 'both' or 'none'. The distance of the line from the center of each color-cell is proportional to the size of the measurement. Defaults to 'column'.

Try setting trace="none" ... ?

Upvotes: 2

Related Questions