Wednesday, 15 July 2015

subplot within a region of a plot in r -



subplot within a region of a plot in r -

> 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

the above table gives x(1st column) , y(2nd column) coordinates of plot want plot.

require(mass) # sammon using generated above coordinates require(deldir) # voronoi tessellations dd <- deldir(d[,1], d[,2]) # voronoi tessellations plot(dd,wlines="tess") # give me tessellations

i want next tessellations plotted in 1 part in above tessellation. can lines form tessellations using dd$dirsgs. in each line there in tessellation given end points. first 4 columns of gives x1,y1 , x2,y2 coordinates respectively. these coordinates end points of line. using info can plot next sub-tessellation within 1 part in above tessellation.

for next sub-tessellation, can generate coordinates of choice. want them in 1 part of above plotted tessellation.

ind 1 , ind2 in dd$dirsgs gives points in 'd' separated line represented first 4 columns of dd$dirsgs.

for example, if want plot sub-tessellation in plot containing first point in d, rows 1,2,9,12,17 rows form boundary first point in d. using information, can plot sub-tessellation within region? –

i think have covered things requisite understand problem. if there more info have not included please allow me know. give information.

the way understand (and mean if understood correctly question), because plot.deldir allows argument add=true passed, can done directly.

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")

first let's extract info polygon: noticed in comments need more processing thought since polygons in plot.deldir plotted line line , not polygon after polygon order of lines scrambled in dd$dirsgs.

ddd <- as.matrix(dd$dirsgs[dd$dirsgs$ind2==1,1:4]) d1poly <- rbind(ddd[1,1:2],ddd[1,3:4]) for( 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

let's create random info in polygon of involvement using bundle splancs:

library(splancs) rd <- csr(as.matrix(d1poly),10) # 10 random points in 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 add together coordinates of point 1 s part of sub-tessellation plot(dd, wlines="tess") plot(rdd, add=true, wlines="tess")

edit concerning restricting lines within boundary, solution can think of ugly workaround: drawing first subtesselation, hiding outside of polygon of involvement , plotting global tesselation.

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 first point of d1poly oriented toward upper left corner: if oriented otherwise order of plotlim has changed accordingly polygon(extpoly, border=na, col="white") plot(dd, wlines="tess", add=true)

r plot voronoi tessellation

No comments:

Post a Comment