Last data update: 2014.03.03

R: Calculate the Voronoi (Dirichlet) Tesselation for a Set of...
calcVoronoiR Documentation

Calculate the Voronoi (Dirichlet) Tesselation for a Set of Points

Description

Calculate the Voronoi (Dirichlet) tesselation for a set of points.

Usage

calcVoronoi (xydata, xlim = NULL, ylim = NULL, eps = 1e-09, frac = 0.0001)

Arguments

xydata

a data frame with columns X and Y containing the points.

xlim

range of X-coordinates; a bounding box for the coordinates.

ylim

range of Y-coordinates; a bounding box for the coordinates.

eps

the value of epsilon used in testing whether a quantity is zero.

frac

used to detect duplicate input points, which meet the condition abs(x1-x2) < frac*(xmax-xmin) and abs(y1-y2) < frac*(ymax-ymin).

Details

This routine ignores all columns other than X and Y.

If the user leaves xlim and ylim unspecified, the function defaults to the range of the data with each extent expanded by ten percent of the range.

This function sets the attribute projection to 1 and the attribute zone to NULL as it assumes this projection in its calculations.

Value

PolySet with columns PID, POS, X, and Y.

See Also

addPoints, addPolys, calcArea, calcCentroid, calcConvexHull, calcMidRange, calcSummary, locateEvents, plotMap, plotPoints, plotPolys.

Examples

local(envir=.PBSmapEnv,expr={
  oldpar = par(no.readonly=TRUE)
  #--- create some EventData
  events <- as.EventData(data.frame(
    EID=1:200, X=rnorm(200), Y=rnorm(200)), projection=1)
  #--- calculate the Voronoi tesselation
  polys <- calcVoronoi(events)
  #--- create PolyData to color it based on area
  polyData <- calcArea(polys)
  names(polyData)[is.element(names(polyData), "area")] <- "Z"
  colSeq <- seq(0.4, 0.95, length=4)
  polyData <- makeProps(polyData,
    breaks=quantile(polyData$Z,c(0,.25,.5,.75,1)),
    propName="col", propVals=rgb(colSeq,colSeq,colSeq))
  #--- plot the tesselation
  plotMap(polys, polyProps=polyData)
  #--- plot the points
  addPoints(events, pch=19)
  par(oldpar)
})

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(PBSmapping)

-----------------------------------------------------------
PBS Mapping 2.69.76 -- Copyright (C) 2003-2016 Fisheries and Oceans Canada

PBS Mapping comes with ABSOLUTELY NO WARRANTY;
for details see the file COPYING.
This is free software, and you are welcome to redistribute
it under certain conditions, as outlined in the above file.

A complete user guide 'PBSmapping-UG.pdf' is located at 
/home/ddbj/local/lib64/R/library/PBSmapping/doc/PBSmapping-UG.pdf

Packaged on 2015-04-23
Pacific Biological Station, Nanaimo

All available PBS packages can be found at
http://code.google.com/p/pbs-software/

To see demos, type '.PBSfigs()'.
-----------------------------------------------------------


> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PBSmapping/calcVoronoi.Rd_%03d_medium.png", width=480, height=480)
> ### Name: calcVoronoi
> ### Title: Calculate the Voronoi (Dirichlet) Tesselation for a Set of
> ###   Points
> ### Aliases: calcVoronoi
> ### Keywords: manip
> 
> ### ** Examples
> 
> local(envir=.PBSmapEnv,expr={
+   oldpar = par(no.readonly=TRUE)
+   #--- create some EventData
+   events <- as.EventData(data.frame(
+     EID=1:200, X=rnorm(200), Y=rnorm(200)), projection=1)
+   #--- calculate the Voronoi tesselation
+   polys <- calcVoronoi(events)
+   #--- create PolyData to color it based on area
+   polyData <- calcArea(polys)
+   names(polyData)[is.element(names(polyData), "area")] <- "Z"
+   colSeq <- seq(0.4, 0.95, length=4)
+   polyData <- makeProps(polyData,
+     breaks=quantile(polyData$Z,c(0,.25,.5,.75,1)),
+     propName="col", propVals=rgb(colSeq,colSeq,colSeq))
+   #--- plot the tesselation
+   plotMap(polys, polyProps=polyData)
+   #--- plot the points
+   addPoints(events, pch=19)
+   par(oldpar)
+ })
Loading required package: deldir
deldir 0.1-12

     PLEASE NOTE:  The components "delsgs" and "summary" of the
 object returned by deldir() are now DATA FRAMES rather than
 matrices (as they were prior to release 0.0-18).
 See help("deldir").
 
     PLEASE NOTE: The process that deldir() uses for determining
 duplicated points has changed from that used in version
 0.0-9 of this package (and previously). See help("deldir").


> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>