
Last chance! 50% off unlimited learning
Sale ends in
densityplot(formula, data, n = 50, plot.points = TRUE, ref = FALSE, ...)
~ x | g1 * g2 * ...
indicating that density plots of x
should be produced
conditional on the levels of the variables g1,g2,...
.
x
must be numeric, and each of x
values
should be plotted.density
(if the default panel function
is used).print.trellis
.trellis.args
for description of other
valid arguments. The density estimate is actually calculated using the
function density
, and all arguments accepted by it can be
passed (as ...
) in the call to densityplot
to control
the output. See documentation of density
for details. (Note: The
default value of the argument n
of density
is changed to
50.)trellis.args
, density
,
panel.densityplot
,
panel.mathdensity
,Lattice
data(singer)
densityplot( ~ height | voice.part, data = singer, layout = c(2, 4),
xlab = "Height (inches)", bw = 5)
## Using a predefined panel function to fit a normal distribution
densityplot( ~ height | voice.part, data = singer, layout = c(2, 4),
xlab = "Height (inches)",
ylab = "Kernel Density/ Normal Fit",
main = list("Estimated Density", cex = 2, col = "DarkOliveGreen"),
panel = function(x, ...) {
panel.xyplot(x = jitter(x),
y = rep(0, length(x)))
panel.densityplot(x, ...)
panel.mathdensity(dmath = dnorm,
args = list(mean=mean(x),sd=sd(x)))
} )
Run the code above in your browser using DataLab