2

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)

I get the below picture:

enter image description here

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

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

Thank you.

Arun
  • 625
  • 3
  • 10
  • 20

1 Answers1

3

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.

Hope that'll help!

sam
  • 158
  • 7