getContourLines {contoureR}R Documentation

Get Contour Lines (data.frame)

Description

The following routine produces contour lines for a set of non-regular x,y and z values. via utilizing a Deleaunay Mesh strung between the supplied x,y coordinates in order to produce iso-contour 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 / fine-grained 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 data-frame object can be provided for x, which will be used in preference to the y and z arguments. These do NOT need to be in any particular order nor do they need to be regular.

z

numeric Data for z coordinate (the coordinate to model)

nlevels

An integer number of bins to split the data into iff levels or binwidth have not been specified.

binwidth

The desired width of the bins, if specified, will override nlevels.

levels

A numeric vector of the explicitly specified levels (z values) to contour, by specifying this argument, it will override nlevels and/or binwidth. If this argument is provided, the stacking order of the contours will be preserved in the order of first occurence within the supplied vector.

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 x-coordinates of the contour

y

The y-coordinates of the contour

z

The z-coordinates of the contour (ie value of the level)

Group

The unique identifyer for each independent contour path, calculated as being the interaction between LID and GID

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^2-y^2))
df.cnt = getContourLines(df)
ggplot(data=df.cnt,aes(x,y,group=Group,colour=z)) + geom_path()

[Package contoureR version 1.0.5 Index]