[R] Help with hclust() and plot()

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Fri May 21 12:53:10 CEST 2004


Hi

Thanks again, but it *still* doesn't work!  I used the following
commands:

> eucomplete <- hclust(d = dist(p[, 2:13], method = "euclidean"), method
= "complete")
> eucomplete$labels
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13"
"14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24"
> eucomplete$labels <- p[,1]
> eucomplete$labels
 [1] NB Hippo S2_824   ME7 Hippo S2_0    ME7 Hippo S2_949  ME7 Hippo
S2_952
 [5] ME7 Hippo S2_823  NB Hippo S2_819D  ME7 Hippo S2_772D ME7 Hippo
S2_#003
 [9] NB Hippo S2_818D  NB Hippo S2_1     NB Hippo S2_#010  NB Hippo
S2_775D
[13] NB Hippo S2_774D  NB Hippo S2_#009  NB Hippo S2_950   NB Hippo
S2_826
[17] NB Hippo S2_#007  NB Hippo S2_951   ME7 Hippo S2_#004 ME7 Hippo
S2_820D
[21] ME7 Hippo S2_#005 ME7 Hippo S2_773D ME7 Hippo S2_#006 ME7 Hippo
S2_822D
24 Levels: ME7 Hippo S2_#003 ME7 Hippo S2_#004 ... NB Hippo S2_951
> plot(as.dendrogram(eucomplete))

I get a lovely formatted dendrogram but the labels are still numbers
1-24! :-(

As can be seen, I have changed eucomplete$labels to be the text I want,
but the plot command still writes out numbers :-(

>plot(eucomplete)

Does work, and I get the right labels.  But I want a dendrogram!

Thanks in advance for your help

Mick



-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj at PDF.COM] 
Sent: 20 May 2004 19:04
To: michael watson (IAH-C)
Cc: R-Help (E-mail)
Subject: Re: [R] Help with hclust() and plot()




michael watson (IAH-C) wrote:

> Hi
> 
> Thanks for that!  BUT if I use as.dendrogram, I can't use my labels 
> anymore!
> 
> 
>>plot(hclust(...etc), labels=p[,1])
> 
> 
> Works fine.  But:
> 
> 
>>plot(as.dendrogram(hclust(...etc)), labels=p[,1])
> 
> 
> Gives me errors:
> 
> Error in axis(side, at, labels, tick, line, pos, outer, font, vfont, 
> lty,  :
> 	location and label lengths differ, 6 != 24
> 
> I have 24 labels.  I have no idea where it gets 6 from!
> 
> My 'dendrogram' has '2 branches and 24 members total'.
> 
> SOOO, how do I get my dendrogram horizontal, or vertical for that 
> matter, with useful labels instead of 1,2,3,4,5,etc
> 
> Thanks in advance for your help!
> 
> Mick
> 

Mick,
   Change the labels in hclust first:

data(USArrests)
hc <- hclust(dist(USArrests), "ave")
hc$labels <- 1:50
dend1 <- as.dendrogram(hc)
plot(dend1, horiz = TRUE)

--sundar




More information about the R-help mailing list