Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Plot smaller clusters from hclust

Tags:

r

I have 250 objects and I used h <- hclust(distance.matrix, method = "single") to obtain a hclust object. If I plot the dendrogram from h, it is just a mess since there are too many objects and the labels just get squashed together.

Suppose I am interested in particular groups of cluster

Now, I know we can use cutree to cut a tree, e.g., as resulting from hclust, into several groups by specifying the desired number(s) of groups.

But how can I obtain a dendrogram for those smaller groups of clusters in R separately?

like image 237
mynameisJEFF Avatar asked Sep 13 '13 14:09

mynameisJEFF


1 Answers

You could convert your hclust object into a dendrogram and use cut (see ?cut.dendrogram for details):

hc <- hclust(dist(USArrests), "ave")
plot(hc)

enter image description here

## cut at height == 100
d <- cut(as.dendrogram(hc), h=100)
## cut returns a list of sub-dendrograms
d
#$upper
#'dendrogram' with 2 branches and 2 members total, at height 152.314 
#
#$lower
#$lower[[1]]
#'dendrogram' with 2 branches and 16 members total, at height 77.60502 

#$lower[[2]]
#'dendrogram' with 2 branches and 34 members total, at height 89.23209 

par(mfrow=c(1, 2))
plot(d$lower[[1]])
plot(d$lower[[2]])
par(mfrow=c(1, 1))

enter image description here

like image 53
sgibb Avatar answered Oct 20 '22 04:10

sgibb