6

everyone. I have a problem in plotting silhouette chart in R.

It is my code.

#k-means clustering
#install.packages("cluster")
library(cluster)
kc <- kmeans(nsoap, centers=3)

dissE <- daisy(nsoap)
sk <- silhouette(kc$cl,dissE)

plot(sk)
dev.off()

I just got this result. It is without the contents...

enter image description here

How can I overcome this problem?

Thank you:)

LyzandeR
  • 35,731
  • 12
  • 70
  • 82
user5431097
  • 69
  • 1
  • 3
  • Possible duplicate of [Make silhouette plot legible for k-means](https://stackoverflow.com/questions/32570693/make-silhouette-plot-legible-for-k-means) – TheSciGuy May 15 '19 at 15:09

2 Answers2

8

Posting answer as this was the top result for a google search on this problem.

This is an issue with how the plot is rendered in RStudio.

This post (https://stackoverflow.com/a/34404740/7687105) shows how to set border = NA in the call to plot() to cause the plot to render correctly.

Another option used here (https://stackoverflow.com/a/34110332/7687105) is to call windows() in RStudio to get a separate window for graphics that plots the Silhouette Coefficients correctly without using the border= option.

Ryan Cole
  • 103
  • 1
  • 7
-1

Try it with the argument col = "darkblue". For example:

plot(sk, col="darkblue")

and then you will see the plot in light color if you focus your sigth.

Peter
  • 8,127
  • 6
  • 53
  • 92