densityPlot {car} | R Documentation

## Nonparametric Density Estimates

### Description

`densityPlot` contructs and graphs nonparametric density estimates, possibly conditioned on a factor. It is a wrapper for the standard R `density` function.

### Usage

    densityPlot(x, ...)

    ## Default S3 method:
    densityPlot(x, g, bw = "SJ", adjust=1,
        kernel = c("gaussian", "epanechnikov", "rectangular",
                   "triangular", "biweight", "cosine", "optcosine"),
        xlab = deparse(substitute(x)), ylab = "Density", col = palette(),
        lty = seq_along(col), lwd = 2, grid=TRUE,
        legend.location = "topright", legend.title = deparse(substitute(g)),
        show.bw = FALSE, rug = TRUE, ...)

    ## S3 method for class 'formula'
    densityPlot(formula, data = NULL, subset, na.action = NULL, xlab, ylab, ...)

### Arguments

`x` | a numeric variable, the density of which is estimated.
`g` | an optional factor to divide the data.
`formula` | an R model formula, of the form `~ variable` to estimate the unconditional density of `variable`, or `variable ~ factor` to estimate the density of `variable` within each level of `factor`.
`data` | an optional data frame containing the data.
`subset` | an optional vector defining a subset of the data.
`na.action` | a function to handle missing values; defaults to the value of the R `na.action` option, initially set to `na.omit`.
`bw` | the bandwidth for the density estimate(s); either the quoted name of a rule to compute the bandwidth, or a numeric value; the default is `"SJ"`; if plotting by groups, `bw` may be a vector of values or rules, one for each group. See `density` and `bw.SJ` for details.
`adjust` | a multiplicative adjustment factor for the bandwidth; the default, `1`, indicates no adjustment; if plotting by groups, `adjust` may be a vector of adjustment factors, one for each group.
`kernel` | kernel function; the default is "gaussian" (see `density`).
`xlab` | label for the horizontal-axis; defaults to the name of the variable `x`.
`ylab` | label for the vertical axis; defaults to `"Density"`.
`col` | vector of colors for the density estimate(s); defaults to the color `palette`.
`lty` | vector of line types for the density estimate(s); defaults to the successive integers, starting at 1.
`lwd` | line width for the density estimate(s); defaults to 2.
`grid` | if `TRUE` (the default), grid lines are drawn on the plot.
`legend.location` | location for the legend when densities are plotted for several groups; defaults to `"upperright"`; see `legend`.
`legend.title` | label for the legend, which is drawn if densities are plotted by groups; the default is the name of the factor g.
`show.bw` | if `TRUE`, show the bandwidth(s) in the horizontal-axis label or (for multiple groups) the legend; the default is `FALSE`.
`rug` | if `TRUE` (the default), draw a rug plot (one-dimentional scatterplot) at the bottom of the density estimate.
`...` | arguments to be passed to `plot`.

### Value

These functions return `NULL` invisibly and draw graphs.

### Author(s)

John Fox jfox@mcmaster.ca

### References

W. N. Venables and B. D. Ripley (2002) Modern Applied Statistics with S. New York: Springer.

### See Also

`density`, `bw.SJ`, `link{plot.density}`

### Examples

    densityPlot(~ income, show.bw=TRUE, data=Prestige)
    densityPlot(income ~ type, data=Prestige)

[Package car version 2.1-2 Index]