We can also plot the assigned clusters with the original data, to see if there are any problems with cluster assignment.
First, we need to append the cluster assignment to the original dataset:
#append the clusters the original data append.clust <- data.frame(x, clusters3,clusters5,clusters7)
For illustration purposes, let's sample from the append.clust dataset. We will set the sample size to 100, but you can set it to any number that makes the diagram readable:
library(cluster) set.seed(1020) sampleit <- append.clust[sample(nrow(append.clust), 100), ]