我想在我的群集中添加一个Voronoi图。也就是说,我想在我的星团,质心+ Voronoi区域有一个情节。有一个简单的方法吗?
我试过了:
x<-c(4,7,9,2,3,3,7,7,8,8,9,9)
y<-c(6,3,3,6,5,7,2,9,4,9,2,8)
mat<-cbind(x,y)# defining matrix
Kmeans<-kmeans(mat,centers=3) # with 3 centroids
plot(x,y,col=Kmeans$cluster,pch=19,cex=2)
points(Kmeans$centers,col=1:3,pch=3,cex=3,lwd=3)
library(tripack)
test<-voronoi.mosaic(x,y)
plot(x,y,col=Kmeans$cluster,pch=19,cex=2)
plot(test)
在这里,我只是不知道如何将它们结合起来以产生合理的情节。
答案 0 :(得分:2)
你的意思是只是将一个绘制在另一个之上?
您在x和y上使用voronoi.mosaic而不在群集上使用voronoi.mosaic。我不知道这对你有什么帮助,只能在另一个上面绘制一个你需要做的事情:
library(tripack)
x<-c(4,7,9,2,3,3,7,7,8,8,9,9)
y<-c(6,3,3,6,5,7,2,9,4,9,2,8)
mat<-cbind(x,y)# defining matrix
Kmeans<-kmeans(mat,centers=3) # with 3 centroids
test<-voronoi.mosaic(x,y)
plot(x,y,col=Kmeans$cluster,pch=19,cex=2)
points(Kmeans$centers,col=1:3,pch=3,cex=3,lwd=3)
par(new=T)
plot(test)
最初,我认为你想要绘制星团和质心,我做了一些完全不同的事情。你也可以在编辑中检查它。