[R] Help with hclust() and plot()
michael watson (IAH-C)
michael.watson at bbsrc.ac.uk
Fri May 21 13:12:21 CEST 2004
OK, I have it working now
I just read in my data a little differently and now it works
HOWEVER, now my labels shoot off the end of the plot - so the labels are
truncated as they hit the edge of the window. This happens for both
horizontal and vertical dendrograms
I guess this is an argument to plot that I need to set, but which one ?
:-(
Thanks
Mick
-----Original Message-----
From: michael watson (IAH-C)
Sent: 21 May 2004 11:53
To: sundar.dorai-raj at pdf.com
Cc: R-Help (E-mail)
Subject: RE: [R] Help with hclust() and plot()
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
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list