我的理解方式(以及我的意思是如果我正确理解你的问题),因为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")
首先让我们来提取数据的多边形:当你在需要它,我以前想,既然在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")
编辑
关于限制边界内的线,唯一的解决办法我可以想到的是一个非常丑陋的解决方法:首先绘制子细分,然后隐藏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)
我想答案就在于通过边界到三月场。 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
par函数的mar参数给出了一个矩形作为边界,但是在上述曲面细分中,我可以有5条或更多线条形成特定区域的边界。我还使用了'TeachingDemos'包的'subplot'功能,但不适用于我的情况。你也可以尝试'subplot',看看你们是否找到任何东西 – dp758 2013-02-12 13:47:11
你有没有尝试mar少于4个变量?我相信它可能会持续到无限。如果发生这种情况,那么它也可能接受更多。试一试! – jackStinger 2013-02-12 14:18:14