[英]How to assign different colors to observation points in different clusters using R's clusplot
http://stat.ethz.ch/R-manual/R-devel/library/cluster/html/clusplot.default.html上的R文檔並不能幫助我。 碼:
somedata = read.data("somefile.tsv")
clustered = kmeans(somedata, 5)
library(cluster)
clusplot(somedata, clustered$cluster, cex=0.1, ..??whatshouldgohere??..)
使用col.p
參數:
clusplot(somedata, clustered$cluster, cex=1, col.p=clustered$cluster)
您可以使用col.p參數,就像David在上面已經說過的那樣:
clusplot(somedata, clustered$cluster, cex=1.0, col.p=c ("steelblue", "darkred", "darkgreen"))
這將為列表中指定的顏色為觀察點分配不同的顏色。
檢查一下:
data(iris)
iris.x <- iris[, 1:4]
cl3 <- pam(iris.x, 3)$clustering
op <- par(mfrow= c(2,2))
clusplot(iris.x, cl3, color = TRUE, cex=0.7, col.p=c ("steelblue", "darkred", "darkgreen"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.