[R] Cluster analysis: hclust manipulation possible?

Jopi Harri jopi.harri at utu.fi
Tue Nov 17 16:41:24 CET 2009


On 16.11.2009 19:13, Charles C. Berry wrote:
>> The question: Can this be accomplished in the *dendrogram plot*
>> by manipulating the resulting hclust data structure or by some
>> other means, and if yes, how?
> 
> Yes, you need to study
> 
>  	?hclust
> 
> particularly the part about 'Value' from which you will see what needs 
> modification.
>  
> Here is a very simple example:
> 
>> res <- hclust(dist(1-diag(3)*rnorm(3)))
>> plot(res)
>> res2 <- res
>> res2$merge <- rbind(-cbind(1:3,4:6), matrix(ifelse( res2$merge<0, -res2$merge, res2$merge+sum(res2$merge<0)),2))
>> res2$height <- c(rep(0,3), res2$height)
>> res2$order <- as.vector( rbind(res2$order,(4:6)[res2$order]) )
>> plot(res2)
>> str( res )
>> str( res2 )


Dear Chuck,

Many thanks for spending your valuable time in the suggestions
and the example. However, the drawback is that as a humanist I
have been having considerable difficulties in figuring out what
exactly to do. After hours of experimenting I could modify
another dendrogram (without crashing R), but still fail to get
the result I want to: the added leaf is not attached to where I
am intending to but instead, another adjacent leaves have their
height turned to 0.

The question, to put it more clearly perhaps: Is there any
straightforward procedure to just add a single leaf to any
dendrogram, next to an existing leaf at the height 0, and if
there is, what might that be?

As of now, it seems that the $merge has to be modified correctly,
but what is the exact strategy, if there is one (other than
redoing the whole clustering by hand)?

> Alternatively, you could use as.dendrogram( res ) as the point of 
> departure and manipulate the value.

Possibly, yes, but I am even less well-equipped with editing that
sort of a data type.


Sincerely,


Jopi Harri
Musicologist
University of Turku
Finland




More information about the R-help mailing list