Clustering: Tutorial Examples and Advanced Visualizations

Note: Sources for these notes:

Load packages and USArrests dataset:

require("cluster")
## Loading required package: cluster
require("factoextra")
## Loading required package: factoextra
## Loading required package: ggplot2
require("magrittr")
## Loading required package: magrittr
data("USArrests")

Distances and hierarchical clustering

Use new methods for distance computation and visualization

distances <- get_dist(USArrests, stand = TRUE, method = "pearson")
fviz_dist(distances, 
   gradient = list(low = "blue", mid = "white", high = "red"))

The conventional hierarchical clustering:

hc <- hclust(distances, method="ave")
plot(hc)

You may later decide that two clusters are OK:

plot(hc)
rect.hclust(hc, k=2)