Next: graphicshelp() Up: Graphics Macros Help File Previous: ellipse()   Contents


info <- findcontour(x,y,vals,levels [,linefrom:T]), REAL vectors x, y,
  and levels, all with no MISSING values, REAL matrix vals

Keywords: contour graphs
After drawing a contour plot of a surface by contourplot() or plotting
the results from repeated calls to contour(), you can use findcontour()
to identify contours with the mouse so that they can be labeled with the
contour level.

info <- findcontour(x,y,vals,levels) attempts to identify the contour
line (level curve) nearest the point (x0,y0) you select using the mouse.

x and y are non-MISSING REAL vectors defining a grid of points and
levels is a non-MISSING vector defining the levels of contours in the

vals is a nrows(x) by nrows(y) REAL matrix, possibly with MISSING
values, of surface heights with vals[i,j] = height of the surface at
(x[i],y[i]).  If the surface is not defined or is infinite at
(x[i],y[j]), vals[i,j] should be MISSING.

Normally, findcontour(x,y,vals,levels) is used after contourplot(x,y,

info is set to structure(x:x0, y:y0, value:val0, level:level0), where
(x0, y0) is the point selected, val0 is the interpolated height of the
surface at (x0,y0), and level0 is the element of levels closest to
val0.  If the point selected is close to a contour, level0 should be
the level of the contour.  If the point selected is in the rectangle
defined by x[i], x[i+1] and y[j], y[j+1] and v[i,j], v[i+1,j], v[i,j+1]
and  v[i+1,j+1] are all MISSING, val0 and level0 will both be MISSING.

You can label a contour by

  Cmd> info <- findcontour(x,y,vals,levels)

  Cmd> addstrings(info$x,info$y,paste(info$level,format:".3f"))

info <- findcontour(x,y,vals,levels,linefrom:T) does the same except you
use Mouse() to define a line to be drawn from a contour to a label.
First select a point (x0,y0) close to the contour and then the point
(x1,y1) where the label should be.

With linefrom:T, info is set to structure(x:vector(x0,x1),
y:vector(y0,y1), value:val0, level:level0) where val0 is the
interpolated surface height at (x0,y0) and level0 is the contour level
nearest to val0.

You can label a contour by

  Cmd> info <- findcontour(x,y,vals,levels,linefrom:T)

  Cmd> addlines(info$x,info$y, show:F)

  Cmd> addstrings(info$x[2],info$y[2],paste(info$level,format:".3f")

You can avoid direct use of findcontour() by using 'label:T' on
contourplot().  This results in findcontour() being called once for
every contour actually drawn, omitting contours whose levels are outside
the range of val.

See also contourplot(), contour(), Mouse().

Gary Oehlert 2003-01-15