smoothcontour {cooltools}R Documentation

Draw smoothed contours

Description

Draw smoothed iso-countours for a density field. The contours are computed using the contourLines routine and smoothed using the smooth.spline function. Both open and closed contour lines are handled correctly.

Usage

smoothcontour(
  x = seq(0, 1, length.out = nrow(z)),
  y = seq(0, 1, length.out = ncol(z)),
  z,
  levels,
  smoothing = 0.5,
  min.radius = 1,
  lwd = 1,
  lty = 1,
  col = "black",
  ...
)

Arguments

x, y

vectors containing the locations of grid lines at which the values of z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used.

z

matrix representing the density field on which the contours are plotted.

levels

vector of the iso-contour levels.

smoothing

value between 0 and 1 specifying the degree of smoothing.

min.radius

numerical value. If larger than 0, all contours with a mean radius (in pixels) below min.radius are removed.

lwd

vector of line widths (see par)

lty

vector of line types (see par)

col

vector of colors (see par)

...

additional parameters to be passed to the function lines.

Value

None

Author(s)

Danail Obreschkow

See Also

contourLines, smooth.spline

Examples

set.seed(1)
f = function(x) cos(2*x[1]-x[2]-1)^2*exp(-x[1]^2-x[2]^2-x[1]*x[2])
x = seq(-3,3,length=100)
m = pracma::meshgrid(x)
z = array(Vectorize(function(x,y) f(c(x,y)))(m$Y,m$X)+rnorm(4e4,sd=0.1),dim(m$X))
image(x,x,z,col=terrain.colors(100))
contour(x,x,z,levels=c(0.2,0.5),add=TRUE)
smoothcontour(x,x,z,levels=c(0.2,0.5),lwd=3,smoothing=0.8,min.radius=2)


[Package cooltools version 2.4 Index]