I am using the factoextra library in R to work on K-means clustering. I am able to create my PCA plot showing clustering membership of the data points but I wish to shape my data points using the time variable. I have pasted my dummy code below, it seems that the fviz_cluster fails to recognize the 'Time' variable.
I'd appreciate all help and comments.
k2 <- kmeans(Scaled_data, centers = 2, nstart = 25)
k2$Time <- as.factor(time)
print(names(k2))
print(length(k2$Time))
print(length(k2$cluster))
plot_Obj <- fviz_cluster(k2, data = Scaled_data,
stand = FALSE,
ellipse.type = "norm",
geom = "point",
alpha=0.5,
ggtheme = theme_minimal(),
repel = FALSE,
shape=Time)
print(plot_Obj)
Output:
[1] "cluster" "centers" "totss" "withinss"
"tot.withinss" [6] "betweenss" "size" "iter" "ifault" "Time"
[1] 783
[1] 783
Error:
Error in fviz_cluster(k2, data = Scaled_data, stand = FALSE,
ellipse.type = "norm", : object 'Time' not found
Execution halted