getContourLines {contoureR}  R Documentation 
Get Contour Lines (data.frame)
Description
The following routine produces contour lines for a set of nonregular x,y
and z
values.
via utilizing a Deleaunay Mesh strung between the supplied x,y
coordinates in order to produce
isocontour data representing the third variable, z
. To this end, by using a Deleaunay mesh,
this routine does not require regular x
and y
data, although it can be expected to yield
'better' result, with regular / finegrained data.
Usage
getContourLines(x, y, z, nlevels = 10, binwidth, levels, criticalRatio = 5)
Arguments
x , y 
Numeric data for x and y coordinate, a single matrix or dataframe object can be provided for

z 
numeric Data for z coordinate (the coordinate to model) 
nlevels 
An integer number of bins to split the data into iff 
binwidth 
The desired width of the bins, if specified, will override 
levels 
A numeric vector of the explicitly specified levels (z values) to contour, by specifying this argument,
it will override 
criticalRatio 
When producing the Delaunay Mesh, the quality of the mesh can be poor in the proximity to the convex hull, Del's that have an aspect ratio greater than this value are not considered when producing the contours. In this context, the aspect ratio is defined as the circumradius to twice its inradius, equilateral triangles have an aspect ratio of 1, everything else is larger 
Value
For the function getContourLines(...)
, the return object is a data.frame
obect
representing the contours, assembled in such way to permit easy use within the ggplot2
paradigm.
Such data frame contains seven (7) columns:
LID 
A number representing the level 
GID 
Within each level, a number representing the contour group 
PID 
Within each group, a number representing the path/segment 
x 
The xcoordinates of the contour 
y 
The ycoordinates of the contour 
z 
The zcoordinates of the contour (ie value of the level) 
Group 
The unique identifyer for each independent contour path, calculated as being the
interaction between 
See Also
contourLinesR
, getDelaunayMesh
and getConvexHull
This is a wrapper to the C++
interface function, contourWalker
.
Examples
# Contour Lines for Volcano Data
library(ggplot2)
data(volcano)
x = 1:nrow(volcano)
y = 1:ncol(volcano)
z = expand.grid(x=x,y=y); z$z = apply(z,1,function(xx){ volcano[ xx[1],xx[2] ]} )
df = getContourLines(z)
ggplot(df,aes(x,y,group=Group,colour=z)) + geom_path()
# Contour Lines for a Function
library(ggplot2)
a = 2; b = 2; n = 75
x = y = seq(a,b,by=diff(c(a,b))/(n+1))
df = expand.grid(x=x,y=y)
df$z = with(df,x*y*exp(x^2y^2))
df.cnt = getContourLines(df)
ggplot(data=df.cnt,aes(x,y,group=Group,colour=z)) + geom_path()