You can choose a different distance measure and method while performing hierarchical clustering. For more details, you can refer to the documents for dist and hclust:
> ? dist > ? hclust
In this recipe, we use hclust to perform agglomerative hierarchical clustering; if you would like to perform divisive hierarchical clustering, you can use the diana function:
- First, you can use diana to perform divisive hierarchical clustering:
> dv = diana(customer, metric = "euclidean")
- Then, you can use summary to obtain the summary information:
> summary(dv)
- Lastly, you can plot a dendrogram and banner with the plot function:
> plot(dv)
If you are interested in drawing a horizontal dendrogram, you can use the dendextend package. Use the following procedure to generate a horizontal dendrogram:
- First, install and load the dendextend and magrittr packages (if your R version is 3.1 or higher, you do not have to install and load the magrittr package):
> install.packages("dendextend") > library(dendextend) > install.packages("margrittr") > library(magrittr)
- Set up the dendrogram:
> dend = customer %>% dist %>% hclust %>% as.dendrogram
- Finally, plot the horizontal dendrogram:
dend %>% plot(horiz=TRUE, main = "Horizontal Dendrogram")
The horizontal dendrogram