Thanks Charles. In the meantime, I found out the following code does the trick. But I am wondering if: 1) I might have made a mistake in it somewhere 2) If there are other (smarter) ways of going about this.
Here is the solution I wrote: # ----------------------------------------- order.a.tree <- function(tree) { num.of.leafs <- length(tree$order) for(i in 2:(num.of.leafs-1)) { tree$order <- order( cutree(tree, k = i)) } return(tree) } #Example: a <- list() # initialize empty object # define merging pattern: # negative numbers are leaves, # positive are merged clusters (defined by row number in $merge) a$merge <- matrix(c(-1, -2, -3, -4, 1, 2, -5,-6, 3,4), nc=2, byrow=TRUE ) a$height <- c(1, 1.5, 3,4,4.5) # define merge heights a$order <- c(1,4,2,3,6,5) # order of leaves(trivial if hand-entered) a$labels <- 1:6# LETTERS[1:4] # labels of leaves class(a) <- "hclust" # make it an hclust object par(mfrow = c(1,2)) plot(a) # look at the result plot(order.a.tree(a)) # ----------------------------------------- Any comments, or other solutions will be very welcomed. Best, Tal ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Sun, Jun 13, 2010 at 7:08 PM, Charles C. Berry <cbe...@tajo.ucsd.edu>wrote: > On Sun, 13 Jun 2010, Tal Galili wrote: > > Hello all, >> >> I manually created an hclust object. >> Now I am looking to reorder the leafs so they won't intersect with each >> other, and would be happy for advises on how to do that. >> > > Have a look at the code for hclust(). > > > If you can instead create an object like 'hcl', then pass the results to > .Fortran("hcass2",...), you should be done. > > HTH, > > Chuck > > >> Here is an example code: >> >> >> #------------------------------------- >> a <- list() # initialize empty object >> # define merging pattern: >> # negative numbers are leaves, >> # positive are merged clusters (defined by row number in $merge) >> a$merge <- matrix(c(-1, -2, >> -3, -4, >> 1, 2, >> -5,-6, >> 3,4), nc=2, byrow=TRUE ) >> a$height <- c(1, 1.5, 3,4,4.5) # define merge heights >> a$order <- c(1,4,2,3,6,5) # order of leaves(trivial if >> hand-entered) >> a$labels <- 1:6# LETTERS[1:4] # labels of leaves >> class(a) <- "hclust" # make it an hclust object >> plot(a) # look at the result >> >> #------------------------------------- >> >> A working order solution in this example would be 1:6. >> The question is how can I find it. >> >> >> Thanks, >> Tal >> >> >> >> >> >> >> >> ----------------Contact >> Details:------------------------------------------------------- >> Contact me: tal.gal...@gmail.com | 972-52-7275845 >> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | >> www.r-statistics.com (English) >> >> ---------------------------------------------------------------------------------------------- >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > Charles C. Berry (858) 534-2098 > Dept of Family/Preventive > Medicine > E mailto:cbe...@tajo.ucsd.edu UC San Diego > http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 > > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.