首页 文章

绘制特定群集的结果

提问于
浏览
-2

我是R的新手,所以我不知道我的查询是否已经重复过 . 我在样本数据集上执行k-means聚类,k = 3,算法返回所需的聚类结果 . 现在我想绘制簇号2的结果,以查看簇2中的成员彼此间隔的距离 . 我该怎么办?谢谢

name <- sample(letters[1:25])
age<-sample(20:50, 25, replace=FALSE)
salary <-sample(2000:10000, 25, replace=FALSE)
demo<-data.frame(name, age, salary)
set.seed(299)
study<-kmeans(demo[,-1],centers = 3)

1 回答

  • 0

    使用 ggplot()

    ggplot(data=demo,
           aes(x=age, y=salary,
               color=factor(study$cluster))) +
      geom_point()
    

    enter image description here

    仅显示群集2:

    ggplot(data=demo[study$cluster==2,],
           aes(x=age, y=salary)) +
        geom_point()
    

    enter image description here

相关问题