R: Kernel density estimation for two continuous variables.
plotDensity3d.fnc
R Documentation
Kernel density estimation for two continuous variables.
Description
The densities of two continuous variables is first computed using the density function from package stats. The outer product of the two densities is computed, which can be plotted as a contour map, a perspective plot, or a dynamic 3d perspective graph.
The type of plot to make. Can be any of "contour" (default), "persp", or, if package rgl is available, "persp3d".
color
The colour scheme to use for plots. One of “topo”, “heat”, “cm”, “terrain”, “gray” or “bw”. Schemes “gray” and “bw” also modify the colors used.
xlab, ylab, zlab
Titles for the axes. N.B. These must be character strings; expressions are not accepted. Numbers will be coerced to character strings.
main
The main title on top of the plot.
cex
The size of label and main text.
alpha
For plot.type = "persp3d", alpha values between 0.0 (fully transparent) to 1.0 (opaque) for the main 3d surface.
lit
Logical, specifying if lighting calculation should take place on geometry.
theta
Angle defining the viewing direction. theta gives the azimuthal direction. Used only if plot.type = "persp".
phi
Angle defining the viewing direction. phi gives the colatitude. Used only if plot.type = "persp".
bw, adjust, kernel, weights, window, width, give.Rkern, n, from, to, cut, na.rm
See help page to function density.
...
Further arguments passed to functions image, contour, persp, or persp3d.
Details
See help page to the density function as well as to Duncan Murdoch's persp3d function for more information. To save screenshots of "persp3d" plots (after plotting), use function rgl.snapshot (produces png files) or function rgl.postscript (produces eps files).
Value
Either a contour map or a (dynamic) perspective plot. Invisibly returns
x
The numeric vector supplied in argument x.
y
The numeric vector supplied in argument y.
xd
The density object tied to vector x.
yd
The density object tied to vector y.
mat
The outer product of the x and y densities in matrix format.