Hello I am trying to answer this question:
cluster the data into 4 clusters using kmeans. Visualize your cluster solution in a biplot by setting the biplot argument xlabs to the vector of cluster membership of your cluster solution.
We are using data from
library("flexclust")
data(milk)
this is what I have started with:
pca_milk <- prcomp(x = milk_matrix, center = TRUE, scale. = FALSE, retx = TRUE)
summary(pca_milk)
pca_milk
km4<-kmeans(milk, centers = 4)
head(km4)
biplot(pca_milk, main = "Biplot", cex = c(0.7,1), scale = TRUE)
I am a bit lost as to how to represent my 4 clusters on my biplot and haven't found much info on r help pages or online. Any help would be greatly appreciated. Thank you :)
I think we are in the same lecture. I solved this by just adding km4$cluster together with the names to the xlabs parameter of the biplot function. Best, Armin