[R] question on silhouette colours

Gordon Robertson grobertson at bcgsc.ca
Thu Aug 25 07:21:22 CEST 2011


I'm fairly new to the silhouette functionality in the cluster package, so apologize if I'm asking something naive. 

If I run the 'agnes(ruspini)' example from the silhouette section of the cluster package vignette, and assign colours to clusters, two clusters have what appear to be incorrect colours in the silhouette plot. 

library(cluster)
data(ruspini)
ar<- agnes(ruspini)
si3<- silhouette(cutree(ar, k = 5), daisy(ruspini))
# 1. This gives a mid-gray silhouette plot, which does not show the problem
plot(si3, nmax = 80, cex.names = 0.5) 
# 2. This gives a multicolour silhouette plot, but there are three black lines/bars in the yellow cluster, and the cluster that should be black is actually yellow?
plot(si3, nmax = 80, cex.names = 0.5, col=c("red","blue","yellow","black","green"))
# 3. Check sorting by writing out sorted results to a file, then plotting from the file
si3.sorted<-sortSilhouette(si3)
write.table(si3.sorted,"/...myPath.../si3.sorted.txt",sep="\t")

Inspecting the si3.sorted.txt file, cluster numbers are ordered as expected (1's then 2's then...), and sil_width's within each cluster appear correctly sorted (descending). Given this, if I load the file into say Mathematica, and plot it with colours, I easily generate a graphic that is like the one from R, but in which all cluster colours are as expected, i.e. there are no black bars in the yellow region, and the cluster that should be black -is- black. 

Again, I apologize if I'm missing something simple. Thanks for your help in understanding this behaviour.

Gordon
--
sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/C/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] cluster_1.14.0
loaded via a namespace (and not attached):
[1] tools_2.13.1

--
Gordon Robertson
BC Cancer Agency Genome Sciences Centre



More information about the R-help mailing list