plot.kde {ks} | R Documentation |
Kernel density estimate plot for 1- to 3-dimensional data.
## univariate ## S3 method for class 'kde': plot(fhat, xlab, ylab="Density function", add=FALSE, ptcol="blue", lcol="black", drawpoints=TRUE, ...) ## bivariate ## S3 method for class 'kde': plot(fhat, display="slice", cont=c(25,50,75), ncont=NULL, cex=0.7, xlab, ylab, zlab="Density function", theta=-30, phi=40, d=4, add=FALSE, drawlabels=TRUE, pch, ptcol="blue", lcol="black", ...) ## trivariate ## S3 method for class 'kde': plot(fhat, cont=c(25,50,75), colors, alphavec, size=3, ptcol="blue", add=FALSE, origin=c(0,0,0), endpts, xlab, ylab, zlab, drawpoints=TRUE, ...)
fhat |
an object of class kde i.e. output from
kde function |
display |
type of display, "slice" for contour plot, "persp" for perspective plot, "image" for image plot (2-d plot) |
cont |
vector of percentages (of maximum height) for contour level curves (2-d plot) |
ncont |
number of contour level curves (2-d plot) |
ptcol |
plotting colour for data points |
lcol |
plotting colour for density estimate |
cex,pch,xlab,ylab,zlab,add |
usual graphics parameters |
theta,phi,d |
graphics parameters for perspective plots (2-d plot) |
drawpoints |
if TRUE then draw data points on density estimate |
drawlabels |
if TRUE then draw contour labels (2-d plot) |
colors |
vector of colours for each contour (3-d plot) |
origin |
origin vector (3-d plot) |
endpts |
vector of end points for each of the 3 axes (3-d plot) |
alphavec |
vector of transparency values (3-d plot) |
size |
size of plotting symbol (3-d plot) |
... |
other graphics parameters |
– The 1-d plot is a standard plot of a 1-d curve. If
drawpoints=TRUE
then a rug plot is added.
– There are three types of plotting displays for 2-d data available, controlled
by the display
parameter.
If display="slice"
then a slice/contour plot
is generated using contour
.
The default contours are at 25%, 50%, 75% or
cont=c(25,50,75)
. The user can also set the number of contour
level curves by changing the value set to ncont
. See examples below.
If display="persp"
then a perspective/wire-frame plot
is generated. The default z-axis limits zlim
are determined by
the range of the z values i.e. default from the usual persp
command.
If display="image"
then an image plot
is generated. The colours are the default from the usual
image
command.
Note the drawpoints
argument fails with 2-d plots. If the data
points shouldn't be added to the plot, set cex=0
.
– For 3-dimensional data, the interactive plot is a series of nested 3-d contours.
The default contours are cont=c(25,50)
, the
default colors
are heat.colors
and the
default opacity alphavec
ranges from 0.1 to 0.5.
origin
is the point where
the three axes meet. endpts
is the vector of the
maximum axis values to be plotted. Default endpts
is the
maxima for the plotting grid from x
.
Plot of 1-d and 2-d kernel density estimates are sent to graphics window. Plot
for 3-d is generated by the misc3d
and rgl
libraries and is sent to RGL window.
Bowman, A.W. & Azzalini, A. (1997) Applied Smoothing Techniques for Data Analysis. Clarendon Press. Oxford.
Simonoff, J. S., (1996) Smoothing Methods in Statistics. Springer-Verlag. New York.
## univariate example x <- rnorm.mixt(n=100, mus=1, sigmas=1, props=1) fhat <- kde(x, h=sqrt(0.09)) plot(fhat) ## bivariate example data(unicef) H.scv <- Hscv(unicef) fhat <- kde(unicef, H=H.scv) layout(rbind(c(1,2), c(3,4))) plot(fhat, display="slice", cont=seq(10,90, by=20), cex=0.3) plot(fhat, display="slice", ncont=8, drawpoints=FALSE, drawlabels=FALSE) plot(fhat, display="persp") plot(fhat, display="image", col=rev(heat.colors(100))) layout(1) ## trivariate example ## Not run: mus <- rbind(c(0,0,0), c(-1,1,1)) Sigma <- matrix(c(1, 0.7, 0.7, 0.7, 1, 0.7, 0.7, 0.7, 1), nr=3, nc=3) Sigmas <- rbind(Sigma, Sigma) props <- c(1/2, 1/2) x <- rmvnorm.mixt(n=100, mus=mus, Sigmas=Sigmas, props=props) H.pi <- Hpi(x) fhat <- kde(x, H=H.pi) plot(fhat, origin=c(-3,-3,-3)) ## End(Not run)