8

Today I have realised that the silhouette plot in the cluster package doesn't display properly in RStudio. A Google search revealed that someone else had had a problem with this:

http://support.rstudio.org/help/discussions/problems/3094-plotsnot-showing-up-in-r-studio

Being new to R, it was unclear to me whether the problem had been resolved in this thread! So my question is: is there a way to get the silhouette plot to display properly in RStudio?

Thanks for any help.

Example script:

library(cluster)
data(xclara)
km <- kmeans(xclara,3)
dissE <- daisy(xclara)
sk <- silhouette(km$cl, dissE)
plot(sk)
4

2 回答 2

11

似乎您引用的线程非常明确:该silhouette包可能有错误png输出,并且 RStudio 与其他一些图形格式不兼容。因此,正如 Josh 所写,您需要在使用 RStudio 时指定“pdf()、quartz() 和 windows() 设备……”。

编辑:所以你需要做的是

pdf('my_nice_plot.pdf')
plot(sk)
dev.off()

它将您的情节直接写入文件。您可以尝试用等替换第一行png('my_nice_plot.png'),因为这些应该也可以。但我怀疑你会在 RStudio 的图形窗口中得到一个干净的绘图,直到他们升级他们的界面。

于 2013-03-04T12:19:29.190 回答
1

这可能只是实际情节的可见性问题:尝试

library(cluster)
data(xclara)
km <- kmeans(xclara[1:100,],3)
dissE <- daisy(xclara[1:100,])
sk <- silhouette(km$cl, dissE)
plot(sk)
于 2014-06-21T15:02:32.433 回答