Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way I understand it (and by that I mean if i understood correctly your question), because <code>plot.deldir</code> allows an argument <code>add=TRUE</code> to be passed, it can be done directly.</p> <pre><code>d&lt;-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 &lt;- deldir(d[,1], d[,2]) plot(dd, wlines="tess") </code></pre> <p><img src="https://i.stack.imgur.com/119dJ.png" alt="enter image description here"></p> <p>First let's extract the data for the polygon: as you noticed in the comments it need more processing that i previously thought since the polygons in <code>plot.deldir</code> are plotted line by line and not polygon after polygon so the order of the lines is scrambled in <code>dd$dirsgs</code>.</p> <pre><code>ddd &lt;- as.matrix(dd$dirsgs[dd$dirsgs$ind2==1,1:4]) d1poly &lt;- rbind(ddd[1,1:2],ddd[1,3:4]) for( i in 2:nrow(ddd)){ x &lt;- ddd[ddd[,1]==d1poly[i,1], 3:4] d1poly &lt;- 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 </code></pre> <p>Let's create some random data in the polygon of interest using package <code>splancs</code>:</p> <pre><code>library(splancs) rd &lt;- 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 &lt;- 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") </code></pre> <p><img src="https://i.stack.imgur.com/WQ70B.png" alt="enter image description here"></p> <p><strong>Edit</strong><br> Concerning restricting the lines within the boundary, the only solution I can think of is a very ugly workaround: drawing first the subtesselation, then hiding the outside of the polygon of interest and then plotting the global tesselation. </p> <pre><code>plot(dd, wlines="tess", col="white", wpoints="none") plot(rdd, wlines="tess", add=TRUE) plotlim &lt;- cbind(par()$usr[c(1,2,2,1)],par()$usr[c(3,3,4,4)]) extpoly &lt;- 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) </code></pre> <p><img src="https://i.stack.imgur.com/uzXZp.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload