在R,spatstat软件包中用于分割tesselations链的软件包?

问题描述:

我想创建聚集点的漂亮数字。是否有一个包将创建点镶嵌之间的分支链?理想情况下,它适合在ggplot中绘图。在R,spatstat软件包中用于分割tesselations链的软件包?

下面是一些示例代码:

#DivideLineExample 
library(spatstat) 

W=owin(c(0,1),c(0,1))   # Set up the Window 
p<-runifpoint(42, win=W)  # Get random points 

ll=cbind(p$x,p$y)    # get lat/long for each point 
zclust=kmeans(ll,centers=4) # Cluster the points spatially into 4 clusters 

K<-pp<-D<-list() 
plot(W,main="Clustered Points") 
for (i in 1:4){     # this breaks up the points into separate ppp objects for each cluster 
    K[[i]]=ll[zclust$cluster==i,] 
    pp[[i]]=as.ppp(K[[i]],W) 
    plot(pp[[i]],col=i,add=TRUE,cex=1.5,pch=16) 
    D[[i]]=dirichlet(pp[[i]])  # This performs the Dirichlet Tessellation and plots 
    plot(D[[i]],col=i,add=TRUE) 
} 

此输出为这样: http://imgur.com/CCXeOEB

Clusters of points without divisions

我正在寻找的是这样的: http://imgur.com/7nmtXjo

Clusters of points with divide chains

我知道算法exists

任何想法/替代品?

+0

感谢您的帮助@Amiramix – Zafar

我写,我想会做你想要什么功能:

divchain <- function (X) { 
    stopifnot(is.ppp(X)) 
    if(!is.multitype(X)) { 
     whinge <- paste(deparse(substitute(X)), 
         "must be a marked pattern with", 
         "factor valued marks.\n") 
     stop(whinge) 
    } 
    X <- unique(X, rule = "deldir", warn = TRUE) 
    w <- Window(X) 
    require(deldir) 
    dd <- deldir(X,z=marks(X),rw=c(w$xrange,w$yrange)) 
    if (is.null(dd)) 
     return(NULL) 
    ddd <- dd$dirsgs 
    sss <- dd$summary 
    z <- sss[["z"]] 
    rslt <- list() 
    nsgs <- nrow(ddd) 
    K <- 0 
    for (i in 1:nsgs) { 
     i1 <- ddd[i,5] 
     i2 <- ddd[i,6] 
     c1 <- z[i1] 
     c2 <- z[i2] 
     if(c1 != c2) { 
      K <- K+1 
      rslt[[K]] <- unlist(ddd[i,1:4]) 
     } 
    } 
    class(rslt) <- "divchain" 
    attr(rslt,"rw") <- dd$rw 
    rslt 
} 

我也写了类“divchain”阴谋方法:

plot.divchain <- function(x,add=FALSE,...){ 
    if(!add) { 
     rw <- attr(x,"rw") 
     plot(0,0,type="n",ann=FALSE,axes=FALSE,xlim=rw[1:2],ylim=rw[3:4]) 
     bty <- list(...)$bty 
     box(bty=bty) 
    } 
    lapply(x,function(u){segments(u[1],u[2],u[3],u[4],...)}) 
    invisible() 

} 

例如:

require(spatstat) 
set.seed(42) 
X <- runifpoint(50) 
z <- factor(kmeans(with(X,cbind(x,y)),centers=4)$cluster) 
marks(X) <- z 
dcX <- divchain(X) 
plot(dirichlet(X),border="brown",main="") 
plot(X,chars=20,cols=1:4,add=TRUE) 
plot(dcX,add=TRUE,lwd=3) 

Dividing chain

让我知道这是否令人满意。对不起,我不能帮你用ggplot的东西;我不会做ggplot。

您可以尝试点多边形测试,例如kirkpatrick数据结构。水平或垂直分割多边形要容易得多。来源:http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/Voronoi/DivConqVor/divConqVor.htm

+0

我不确定你指的是什么过程。请解释。我没有任何功能多边形在多边形测试中做点,我正在寻找一个软件包或解决方法,为每个曲面细分创建多边形。 – Zafar

+0

IMO你overengineer它。简单地计算所有站点的vd并将其与您的集群进行比较。我错过了什么吗? – Bytemain

+0

问题是我正在使用网格数据集,所以如果我这样做,那么我只会得到丑陋的方块,这是不准确的,不是出版质量。 – Zafar