2013-02-12 26 views
2
> d 
     [,1]  [,2] 
1 -0.5561835 1.49947588 
2 -2.3985544 3.07130217 
3 -3.8833659 -4.29331711 
4 3.1025836 5.45359160 
5 0.7438354 -2.80116065 
6 7.0787294 -2.78121213 
7 -1.6633598 -1.17898157 
8 -0.6751930 0.03466162 
9 1.4633841 0.50173157 
10 -3.2118758 0.49390863 

上表给出了我想绘制的图的x(第1列)和y(第2列)坐标。子图在r中的一个区域内

require(MASS)    # for sammon using which i generated the above coordinates 
require(deldir)    # for voronoi tessellations 
dd <- deldir(d[,1], d[,2]) # voronoi tessellations 
plot(dd,wlines="tess")  # This will give me tessellations 

我希望我的下一个细分被绘制在上述镶嵌的一个区域中。我可以使用dd $ dirsgs获取构成曲面细分的线条。在这个曲面中的每一行都会给出它们的终点。这前四列分别给出了x1,y1和x2,y2坐标。这些坐标是线的终点。使用这些数据可以在上面的曲面细分中绘制该区域内的下一个子细分。

对于下一个子细分,您可以生成您选择的坐标。但我只想让他们在上面绘制的镶嵌图的一个区域。

dd $ dirsgs中的ind 1和ind2给出'd'中由dd $ dirsgs的前4列表示的行分隔的点。

例如,如果我们想要绘制包含d中第一个点的图中的子镶嵌细分,那么行1,2,9,12,17就是形成第一个点的边界的行d。使用这些信息,我们可以绘制该区域内的子细分? -

我想我已经涵盖了理解我的问题所必需的所有事情。如果还有更多我没有收录的数据,请告诉我。我会提供这些信息。

+1

我想答案就在于通过边界到三月场。 mar = c(-10,-10,10,10)在两个axii上产生一个在-10和10之间的区域。所以如果我们可以传递坐标的函数,例如c(3-y,4-x,6 + x,2 + y),它可以在行x + y = 3,x + y = 4,y-x = 6和x-y = 2之间产生界限。 – jackStinger 2013-02-12 13:42:06

+1

par函数的mar参数给出了一个矩形作为边界,但是在上述曲面细分中,我可以有5条或更多线条形成特定区域的边界。我还使用了'TeachingDemos'包的'subplot'功能,但不适用于我的情况。你也可以尝试'subplot',看看你们是否找到任何东西 – dp758 2013-02-12 13:47:11

+0

你有没有尝试mar少于4个变量?我相信它可能会持续到无限。如果发生这种情况,那么它也可能接受更多。试一试! – jackStinger 2013-02-12 14:18:14

回答

2

我的理解方式(以及我的意思是如果我正确理解你的问题),因为plot.deldir允许参数add=TRUE被传递,它可以直接完成。

d<-structure(list(V1 = c(-0.5561835, -2.3985544, -3.8833659, 3.1025836, 0.7438354, 
        7.0787294, -1.6633598, -0.675193, 1.4633841, -3.2118758), V2 = 
        c(1.49947588, 3.07130217, -4.29331711, 5.4535916, -2.80116065, 
        -2.78121213, -1.17898157, 0.03466162, 0.50173157, 0.49390863)), .Names =   
        c("V1","V2"), class = "data.frame", row.names = c(NA, -10L)) 

library(MASS) 
library(deldir) 
dd <- deldir(d[,1], d[,2]) 
plot(dd, wlines="tess") 

enter image description here

首先让我们来提取数据的多边形:当你在需要它,我以前想,既然在plot.deldir多边形是由线绘制线和面后不多边形更多的处理意见注意到所以这些行的顺序在dd$dirsgs中被加扰。

ddd <- as.matrix(dd$dirsgs[dd$dirsgs$ind2==1,1:4]) 
d1poly <- rbind(ddd[1,1:2],ddd[1,3:4]) 
for(i in 2:nrow(ddd)){ 
    x <- ddd[ddd[,1]==d1poly[i,1], 3:4] 
    d1poly <- rbind(d1poly, x) 
    } 
d1poly 
     x2  y2 
    -2.096990 1.559118 
    0.303986 4.373353 
x 1.550185 3.220238 
x 0.301414 0.692558 
x -1.834581 0.866098 
x -2.096990 1.559118 

让我们感兴趣的多边形使用包splancs创建一些随机数据:

library(splancs) 
rd <- csr(as.matrix(d1poly),10) # For 10 random points in the polygon containing point 1 
rd 
       xc  yc 
[1,] -1.6904093 1.9281052 
[2,] -1.1321334 1.7363064 
[3,] 0.2264649 1.3986126 
[4,] -1.1883844 2.5996515 
[5,] -0.6929208 0.8745020 
[6,] -0.8348241 2.3318222 
[7,] 0.9101748 1.9439797 
[8,] 0.1665160 1.8754703 
[9,] -1.1100710 1.3517257 
[10,] -1.5691826 0.8782223 

rdd <- deldir(c(rd[,1],d[1,1]),c(rd[,2],d[1,2])) 
# don't forget to add the coordinates of your point 1 so it s part of the sub-tessellation 
plot(dd, wlines="tess") 
plot(rdd, add=TRUE, wlines="tess") 

enter image description here

编辑
关于限制边界内的线,唯一的解决办法我可以想到的是一个非常丑陋的解决方法:首先绘制子细分,然后隐藏poly的外部然后绘制全球镶嵌图。

plot(dd, wlines="tess", col="white", wpoints="none") 
plot(rdd, wlines="tess", add=TRUE) 

plotlim <- cbind(par()$usr[c(1,2,2,1)],par()$usr[c(3,3,4,4)]) 
extpoly <- rbind(plotlim, d1poly) 
#Here the first point of d1poly is oriented toward the upper left corner: if it is oriented otherwise the order of plotlim has to be changed accordingly 

polygon(extpoly, border=NA, col="white") 

plot(dd, wlines="tess", add=TRUE) 

enter image description here

+0

谢谢plannapus :)在我的问题中还有一些限制......但是使用您提供的信息我认为我应该找到解决方案......我会在这方面做更多的工作,如果我有任何问题,我会让你懂。 – dp758 2013-02-13 06:23:32

+0

是否有限制边界内镶嵌线的方法?我不想让他们走出界限 – dp758 2013-02-13 08:12:44

+0

@Chetan我试图找到一种方式,但没有什么明显的想到。我会回到你身边,如果我找到东西 – plannapus 2013-02-13 08:25:37

1

很可能,你要考虑使用的spatstat包对于这一点,因为它可以大大简化制约了新镶嵌到现有镶嵌的瓷砖。然后,您的安装将是这样的:

library(spatstat) 
# Plot the main tessellation and points 
d<-structure(list(V1 = c(-0.5561835, -2.3985544, -3.8833659, 3.1025836, 0.7438354, 
        7.0787294, -1.6633598, -0.675193, 1.4633841, -3.2118758), V2 = 
        c(1.49947588, 3.07130217, -4.29331711, 5.4535916, -2.80116065, 
        -2.78121213, -1.17898157, 0.03466162, 0.50173157, 0.49390863)), .Names =   
        c("V1","V2"), class = "data.frame", row.names = c(NA, -10L)) 

d_points <- ppp(d$V1, d$V2, window=owin(c(-5, 8), c(-6, 6))) 
main_tessellation <- dirichlet(d_points) 
plot(main_tessellation, lty=3) # plot the tessellation 
plot(d_points, add=TRUE) # add the points 

# Plot the interior tessellation and points (color=red so the difference is clear) 
# Arbitrarily choosing the 9th tile from the above tessellation: 
target_poly <- owin(poly=main_tessellation$tiles[[9]]$bdry[[1]]) 

# Generate random set of points within the boundaries of the polygon chosen above 
new_points <- runifpoint(6, win=target_poly) 
# Generate and plot the new tessellation and points 
new_tessellation <- dirichlet(new_points) 
plot(new_tessellation, add=TRUE, col='red') 
plot(new_points, add=TRUE, col='red') 

将产生: enter image description here

看到这个密切相关的问题:Voronoi diagram polygons enclosed in geographic borders