[R] hclust and plot functions work, cutree does not

Peter Langfelder peter.langfelder at gmail.com
Tue Apr 3 17:39:33 CEST 2012


On Tue, Apr 3, 2012 at 2:41 AM, vinod1 <vinod.hegde.c at gmail.com> wrote:
> Sarah,
>
> .       clust_tree=hclust(as.dist(x),method="complete")
> .       plot(clust_tree)
>
> this produces a dendrogram, whereas
> .       clust_tree=hclust(as.dist(x),method="complete")
> .        cut = cutree(clust_tree,k=1:5)
> .        plot(cut)
>
> produces a plot with 2 dots. The dissimilarity matrix x is 100*100 matrix.

What kind of output do you expect?

If you want to see the clustering tree and an indication of which
object belongs to which cluster, install package WGCNA and use the
function plotDendroAndColors. Continuing with Sarah's example, you can
use

hc <- hclust(dist(USArrests))
labels =  cutree(hc, k=1:5)

require("WGCNA")
plotDendroAndColors(hc, labels)

You get the clustering tree plus a color indication of the cluster
each object belongs to in each cut.

You can also produce MDS plots colored by the cluster label.

If you'd like to experiment with more involved ways of identifying
branches (or subtrees) in the dendrogram, I can recommend the article
(warning, shameless plug)

Langfelder P, Zhang B, Horvath S (2007) Defining clusters from a
hierarchical cluster tree: the Dynamic Tree Cut package for R.
Bioinformatics 2008 24(5):719-720

and the package dynamicTreeCut that the short article describes. You
can see some example code at

http://www.genetics.ucla.edu/labs/horvath/CoexpressionNetwork/BranchCutting/

We use this approach in large gene expression data sets.

HTH,

Peter



More information about the R-help mailing list