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

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Thu May 20 18:12:50 CEST 2004


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

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




michael watson (IAH-C) wrote:
> Hi
> 
> When I use plot(hclust(dist..)...)...) etc to create a dendrogram of a

> hierarchial cluster analysis, I end up with a vertical tree.  What do 
> I need to do to get a horizontal tree?
> 
> Also, my users are used to seeing trees who's leaves all "end" at the 
> same place (eg. Like in minitab).  Is this possible in R?
> 
> Thanks
> 
> Mick
> 

Mick,
   If you use as.dendrogram first then the plot method for dendrograms 
has a horizontal option:

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

This also puts the leave at the end.

R version 1.9.0, 2004-05-06
Windows 2000

--sundar




More information about the R-help mailing list