Description Usage Arguments Value See Also Examples
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.
1  getContourLines(x, y, z, nlevels = 10, binwidth, levels, criticalRatio = 5)

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 
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:

A number representing the level 

Within each level, a number representing the contour group 

Within each group, a number representing the path/segment 

The xcoordinates of the contour 

The ycoordinates of the contour 

The zcoordinates of the contour (ie value of the level) 

The unique identifyer for each independent contour path, calculated as being the
interaction between 
contourLinesR
, getDelaunayMesh
and getConvexHull
This is a wrapper to the C++
interface function, contourWalker
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  # 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()

Loading required package: geometry
Loading required package: magic
Loading required package: abind
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.