-----Original Message-----
From: Paul Murrell [mailto:p.murrell at auckland.ac.nz]
Sent: Thursday, August 25, 2005 7:37 PM
To: Wittner, Ben
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] problem building dendrograms to use with heatmap()
Hi
Wittner, Ben wrote:
Hi,
I'm trying to build dendrograms to pass to heatmap().
The dendrograms I build plot properly, but when I pass them to heatmap()
the error message "row dendrogram ordering gave index of wrong length"
Looks like you're not building the dendrograms "properly". Compare
unclass(nr2) with unclass() of a dendrogram from
as.dendrogram(hclust(<something>)). You might need to look closely at
stats:::as.dendrogram.hclust to get it right.
Paul
I looked in the code of heatmap() and saw that the error was due to a
return value from order.dendrogram(), which in turn got a NULL return
unlist(). But I have no idea why unlist() is returning NULL.
I've included code below which reproduces the problem and below that the
from a run of that code on my computer.
Any help would be greatly appreciated. Thanks in advance.
-Ben
########################### begin code
###################################
version
dendro.leaf <- function(label) {
ans <- list()
attr(ans, 'members') <- 1
attr(ans, 'height') <- 0
attr(ans, 'leaf') <- T
attr(ans, 'midpoint') <- 0
attr(ans, 'label') <- label
attr(ans, 'class') <- 'dendrogram'
ans
}
dendro.merge <- function(d1, d2, height) {
ans <- list(d1, d2)
members <- attr(d1, 'members') + attr(d2, 'members')
attr(ans, 'members') <- members
attr(ans, 'height') <- height
attr(ans, 'leaf') <- F
attr(ans, 'midpoint') <- (members - 1)/2
attr(ans, 'class') <- 'dendrogram'
ans
}
lc1 <- dendro.leaf('c1')
lc2 <- dendro.leaf('c2')
lc3 <- dendro.leaf('c3')
nc1 <- dendro.merge(lc1, lc2, 0.1)
nc2 <- dendro.merge(nc1, lc3, 0.2)
plot(nc2)
lr1 <- dendro.leaf('r1')
lr2 <- dendro.leaf('r2')
lr3 <- dendro.leaf('r3')
nr1 <- dendro.merge(lr2, lr3, 0.1)
nr2 <- dendro.merge(lr1, nr1, 0.3)
plot(nr2)
x <- matrix(seq(-1, 1, length.out=9), nrow=3)
rownames(x) <- paste('r', 1:3, sep='')
colnames(x) <- paste('c', 1:3, sep='')
heatmap(x, Rowv=nr2, Colv=nc2, scale='none')
order.dendrogram(nr2)
unlist(nr2)
############### begin output from run of code above ##################
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 2
minor 1.1
year 2005
month 06
day 20
language R
dendro.leaf <- function(label) {
+ ans <- list()
+ attr(ans, 'members') <- 1
+ attr(ans, 'height') <- 0
+ attr(ans, 'leaf') <- T
+ attr(ans, 'midpoint') <- 0
+ attr(ans, 'label') <- label
+ attr(ans, 'class') <- 'dendrogram'
+ ans
+ }
dendro.merge <- function(d1, d2, height) {
+ ans <- list(d1, d2)
+ members <- attr(d1, 'members') + attr(d2, 'members')
+ attr(ans, 'members') <- members
+ attr(ans, 'height') <- height
+ attr(ans, 'leaf') <- F
+ attr(ans, 'midpoint') <- (members - 1)/2
+ attr(ans, 'class') <- 'dendrogram'
+ ans
+ }
lc1 <- dendro.leaf('c1')
lc2 <- dendro.leaf('c2')
lc3 <- dendro.leaf('c3')
nc1 <- dendro.merge(lc1, lc2, 0.1)
nc2 <- dendro.merge(nc1, lc3, 0.2)
plot(nc2)
lr1 <- dendro.leaf('r1')
lr2 <- dendro.leaf('r2')
lr3 <- dendro.leaf('r3')
nr1 <- dendro.merge(lr2, lr3, 0.1)
nr2 <- dendro.merge(lr1, nr1, 0.3)
plot(nr2)
x <- matrix(seq(-1, 1, length.out=9), nrow=3)
rownames(x) <- paste('r', 1:3, sep='')
colnames(x) <- paste('c', 1:3, sep='')
heatmap(x, Rowv=nr2, Colv=nc2, scale='none')
Error in heatmap(x, Rowv = nr2, Colv = nc2, scale = "none") :
row dendrogram ordering gave index of wrong length