Question

Suppose you cluster a Matrix that has a headerline in R, using hclust.

Usually one would get a labeled picture, so to speak, a dendrogram. Is there a way to make the labels of the vectors (which are in the headerline) appear within the dendrogramm?

Was it helpful?

Solution

I suppose you mean column names with headerline. Here a small example:

set.seed(123)
## create example matrix
m <- matrix(runif(200), ncol=10)
## create column names (A-G)
colnames(m) <- LETTERS[1:10]
## calculate distance matrix (transpose matrix, because dist use rows as individual samples)
d <- dist(t(m))
## clustering distance matrix
h <- hclust(d)
## plot it
plot(h)

enter image description here

OTHER TIPS

To get, from a hierarchical clustering hc, a clustering in exactly k clusters, use cutree(hc, k) [translated: cut the clustering tree at height to get k clusters). This will exactly give you the desired vector length n, with contents from {1,...k}. This applies both to hclust() and to agnes() results, the latter from package cluster.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top