We can determine the number of clusters from the dendrogram in the preceding figure. In the first step, we decided that there should be four clusters within the tree using the k=4 attribute in the cutree function. Besides using the number of clusters to cut the tree, you can also specify the height as the cut tree parameter.
Next, we use the table function to count the number of data within each cluster and we find that most of the data is in cluster 2. Lastly, we draw red rectangles around the clusters to show how the data is categorized into the four clusters with the rect.hclust function.