# Reorder clusters
spe.chwo <- reorder.hclust(spe.ch.ward, spe.ch)
# Plot reordered dendrogram with group labels
plot(
spe.chwo,
hang = -1,
xlab = "4 groups",
sub = "",
ylab = "Height",
main = "Chord - Ward (reordered)",
labels = cutree(spe.chwo, k = k)
)
rect.hclust(spe.chwo, k = k)
# Plot the final dendrogram with group colors (RGBCMY...)
# Fast method using the additional hcoplot() function:
hcoplot(spe.ch.ward, spe.ch, lab = rownames(spe), k = 4)
Hints Function reorder.hclust() reorders objects so that their original order in
the dissimilarity matrix is respected as much as possible. This does not affect the
topology of the dendrogram. Its arguments are (1) the clustering object and (2)
the dissimilarity matrix.
When using rect.hclust() to draw boxes around clusters, as in the
hcoplot() function used here, one can specify a fusion level (argument h)
instead of a number of groups (argument k).
Another function called identify.hclust() allows the interactive cut of a
tree at any position where one left-clicks with the mouse. It makes it possible to
extract a list of objects from any given subgroup.
The argument hang = -1 specifies that the branches of the dendrogram will
all reach the value 0 and the labels will hang below that value.
Let us conclude with several other representations of the clustering results
obtained above. The usefulness of these representations depends on the context.
The dendextend package provides various functions to improve the representation of a dendrogram. First, the hclust object must be converted to a dendrogram object. Then, you can apply colours and line options to the branches of the
dendrogram, e.g. based on the final partition (Fig. 4.16).
90
4 Cluster Analysis
spe.chwo <- reorder.hclust(spe.ch.ward, spe.ch)
# Plot reordered dendrogram with group labels
plot(
spe.chwo,
hang = -1,
xlab = "4 groups",
sub = "",
ylab = "Height",
main = "Chord - Ward (reordered)",
labels = cutree(spe.chwo, k = k)
)
rect.hclust(spe.chwo, k = k)
# Plot the final dendrogram with group colors (RGBCMY...)
# Fast method using the additional hcoplot() function:
hcoplot(spe.ch.ward, spe.ch, lab = rownames(spe), k = 4)
Hints Function reorder.hclust() reorders objects so that their original order in
the dissimilarity matrix is respected as much as possible. This does not affect the
topology of the dendrogram. Its arguments are (1) the clustering object and (2)
the dissimilarity matrix.
When using rect.hclust() to draw boxes around clusters, as in the
hcoplot() function used here, one can specify a fusion level (argument h)
instead of a number of groups (argument k).
Another function called identify.hclust() allows the interactive cut of a
tree at any position where one left-clicks with the mouse. It makes it possible to
extract a list of objects from any given subgroup.
The argument hang = -1 specifies that the branches of the dendrogram will
all reach the value 0 and the labels will hang below that value.
Let us conclude with several other representations of the clustering results
obtained above. The usefulness of these representations depends on the context.
The dendextend package provides various functions to improve the representation of a dendrogram. First, the hclust object must be converted to a dendrogram object. Then, you can apply colours and line options to the branches of the
dendrogram, e.g. based on the final partition (Fig. 4.16).
90
4 Cluster Analysis
