smoothcontour: Draw smoothed contours

Description Usage Arguments Value Author(s) See Also Examples

View source: R/smoothcontour.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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

1
2
3
4
5
6
7
8
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)

graphx documentation built on Feb. 3, 2022, 5:07 p.m.

Related to smoothcontour in graphx...