There is no way to (directly) label the individual points using s.class(...)
. As you point out, the label=
argument labels the clusters (point classes), not the individual points.
However, since s.class(...)
uses the plot routines in base R, you can simply add a call to text(...)
:
labs <- rownames(obs.bet$ls)
s.class(obs.bet$ls,fac=factor(data.cluster),grid=F, xlim=c(-4,4))
text(obs.bet$ls,labels=labs,adj=c(-.1,-.8),cex=0.8)
There's a fair amount of tweaking of xlim=
, adj=
, and cex=
to make the labels readable, but it does work.
Here are two alternatives that may be helpful (hopefully).
clusplot(obs.bet$ls,data.cluster,labels=2)
Produces this, which is very similar to your plot, with the points labeled.
Another alternative uses ggplot
:
library(ggplot2)
gg <- cbind(obs.bet$ls,cluster=data.cluster)
gg <- cbind(sample=rownames(gg),gg)
ggplot(gg, aes(x=CS1, y=CS2)) +
geom_point(aes(color=factor(cluster)),size=5) +
geom_text(aes(label=sample),hjust=-0.2) +
geom_hline(yintercept=0,linetype=2) +
geom_vline(xintercept=0,linetype=2) +
scale_color_discrete(name="Cluster") +
xlim(-4,4)