如何添加Voronoi图表? [英] How to add Voronoi diagramm?

查看:160
本文介绍了如何添加Voronoi图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的群集添加一个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)#定义矩阵
Kmeans< -kmeans(mat,center = 3)#with 3个质心
plot(x,y,col = Kmeans $ cluster,pch = 19,cex = 2)
points(Kmeans $ center,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)

这里我只是不知道如何组合他们会产生一个合理的阴谋。

解决方案

你的意思只是一个在另一个之上?

您在x和y上使用voronoi.mosaic,而不是在群集上。我不知道这将如何帮助你,而是将其中一个放在另一个之上,你需要做以下事情:

 库(三包)
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)#定义矩阵
Kmeans< -kmeans(mat ,center = 3)#3个质心

test <-voronoi.mosaic(x,y)
plot(x,y,col = Kmeans $ cluster,pch = 19,cex = 2)
点(Kmeans $ center,col = 1:3,pch = 3,cex = 3,lwd = 3)
par(new = T)
plot(test)



最初,我以为你想绘制集群和质心,我做了一些完全不同的事情。您也可以在编辑中查看。


I would like to add a Voronoi plot to my clusters. That is, I would like to have one plot with my clusters, centroids + the Voronoi regions. Is there a simple way to do it?

I tried:

                    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)

Here I just dont know how to combine them to produce a reasonable plot.

解决方案

You mean just plot one on top of the other?

You are using the voronoi.mosaic on x and y and not on the clusters. I don't know how this will help you but to plot one on top of the other you need to do the following:

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)

Initially, I thought you wanted to plot the clusters and the centroids and I did something completely different. You can check that too in the edits.

这篇关于如何添加Voronoi图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆