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 Michael Watson Head of Informatics Institute for Animal Health, Compton Laboratory, Compton, Newbury, Berkshire RG20 7NN UK Phone : +44 (0)1635 578411 ext. 2535 Mobile: +44 (0)7990 827831 E-mail: michael.watson at bbsrc.ac.uk
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 Michael Watson Head of Informatics Institute for Animal Health, Compton Laboratory, Compton, Newbury, Berkshire RG20 7NN UK Phone : +44 (0)1635 578411 ext. 2535 Mobile: +44 (0)7990 827831 E-mail: michael.watson at bbsrc.ac.uk
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
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
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
Hi Sean I obviously wasn't cut out for this. Just to try it out, I tried:>plot(1:8, 1:8, mar=c(5,4,4,2))(this is the default according to the help) All I got was: "there were twelve warnings">warnings()1: parameter "mar" couldn't be set in high-level plot() function BUT in the help, the example is given as: <highlevel plot> (..., <tag> = <value>) So, I know I must be doing something stupid, but I have no idea what.... Mick -----Original Message----- From: Sean Davis [mailto:sdavis2 at mail.nih.gov] Sent: 21 May 2004 12:30 To: michael watson (IAH-C); sundar.dorai-raj at pdf.com Cc: r-help Subject: Re: [R] Help with hclust() and plot() See ?par. It is a long help, but pay particular attention to par(mar=c(...)). It changes margins on plots. Sean On 5/21/04 7:12 AM, "michael watson (IAH-C)" <michael.watson at bbsrc.ac.uk> wrote:> 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 > > ______________________________________________ > 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 >
Tamas Papp wrote:> On Fri, May 21, 2004 at 07:56:02AM -0400, Sean Davis wrote: > > > The use for par is: > > > > > plot(1:8,1:8) #you must have an open graphics window before > > #par has an effect > > Instead of making a plot you will discard anyway (since you are making > another when par() takes effect), you might want to initialize the > device using the appropriate functions, eg x11(), postscript(), etc.Just issue the par() command, and if no device is open, an x11 window will be opened automatically. Sean Davis's assertion that ``you must have an open graphics window before par has an effect'' simply isn't true. At least it's not true under R 1.8.1 on Solaris nor under R 1.9.0 on Linux. cheers, Rolf Turner rolf at math.unb.ca
Thank you one and all, I have figured it out now; Cheers Sean! -----Original Message----- From: Rolf Turner [mailto:rolf at math.unb.ca] Sent: 21 May 2004 15:13 To: r-help at stat.math.ethz.ch Subject: Re: [R] Help with hclust() and plot() Tamas Papp wrote:> On Fri, May 21, 2004 at 07:56:02AM -0400, Sean Davis wrote: > > > The use for par is: > > > > > plot(1:8,1:8) #you must have an open graphics window before > > #par has an effect > > Instead of making a plot you will discard anyway (since you are making> another when par() takes effect), you might want to initialize the > device using the appropriate functions, eg x11(), postscript(), etc.Just issue the par() command, and if no device is open, an x11 window will be opened automatically. Sean Davis's assertion that ``you must have an open graphics window before par has an effect'' simply isn't true. At least it's not true under R 1.8.1 on Solaris nor under R 1.9.0 on Linux. cheers, Rolf Turner rolf at math.unb.ca ______________________________________________ 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