R中利用cluster簡單的繪制常見聚類離散圖
# 引入cluster庫(clara、fanny) library(cluster) # 聚類散點圖繪制 # 引入factoextra,cluster庫(fviz_cluster) library(ggplot2) library(factoextra) # 確定簇心個數 cluster_num <- 3 # 讀取數據 data <- read.csv("data.csv",header = T) # 調用kmeans算法 km <- kmeans(data,cluster_num) # 調用Clara算法 cl <- clara(data,cluster_num) # 調用模糊C-Means聚類算法 fan <- fanny(data,cluster_num) # 繪圖 #fviz_cluster(km, data, ellipse.type = "norm") fviz_cluster(fan, data)