如何添加 Voronoi 图?

3

我想在我的聚类中添加一个沃罗诺伊图。也就是说,我想要一个包含我的聚类、质心和沃罗诺伊区域的绘图。有没有简单的方法可以实现?

我尝试过:

                    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)

我不知道如何将它们组合起来以产生合理的图表。


也许你正在寻找一条/边界来区分聚类,就像线性判别分析中的那样? - Roman Luštrik
1个回答

2

你的意思是把它们叠在一起吗?

你正在使用voronoi.mosaic对x和y进行操作,而不是对聚类进行操作。我不知道这样做有什么帮助,但如果想要将它们叠在一起,需要按照以下步骤进行:

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)

输入图像描述

一开始,我以为你想绘制聚类和质心,所以我做了完全不同的事情。你也可以在编辑中检查。


是的,就是这样...谢谢。 - user3833190

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接