如何在K中显示行名表示R中的簇图? [英] How to display the row name in K means cluster plot in R?

查看:51
本文介绍了如何在K中显示行名表示R中的簇图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制K均值聚类.下面是我使用的代码.

I am trying to plot the K-means cluster. The below is the code i use.

library(cluster)
library(fpc)

data(iris)
dat <- iris[, -5] # without known classification 
# Kmeans clustre analysis
clus <- kmeans(dat, centers=3)
clusplot(dat, clus$cluster, color=TRUE, shade=TRUE, 
         labels=2, lines=0)

我得到以下图片:

我希望它以行名而不是​​字符显示,而不是行号.我了解这张图片产生的数据如下:

Instead of the row numbers, I want it displayed with a row name in characters. I understand this picture is producing had the data like the below:

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

但是请假定我的工作数据如下所示

However kindly assume that the my work data is like below

         Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Flower1          5.1         3.5          1.4         0.2  setosa
Flower2          4.9         3.0          1.4         0.2  setosa
Flower3          4.7         3.2          1.3         0.2  setosa
Flower4          4.6         3.1          1.5         0.2  setosa
Flower5          5.0         3.6          1.4         0.2  setosa
Flower6          5.4         3.9          1.7         0.4  setosa

我想在可视化中包含flower1,flower2等,而不是序列号.有没有办法实现这一目标?

I want to have the flower1, flower2 etc in the visualization rather than the serial number. Is there a way to achieve this please?

谢谢.

推荐答案

对我来说,当您以row.names(dat) <- paste("flower",row.names(dat))之类的方式重命名行名时,它起作用了.这意味着,如果您的行名以您希望的方式显示,则将正确显示它们.

for me it worked, when you rename the row names in a way like row.names(dat) <- paste("flower",row.names(dat)). This means if your row names are in the way you want them to be, they'll be properly displayed.

希望会有所帮助!

这篇关于如何在K中显示行名表示R中的簇图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆