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
  • 37,047
  • 12
  • 77
  • 87
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

9

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
  • 113
  • 1
  • 8
  • Only the second option works when trying to plot the banner plot of `agnes()` with `plot(..., which.plots=1)`. – Mew May 31 '23 at 09:54
-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,776
  • 6
  • 62
  • 95