The mosaic package adds some additional functionality to
lattice::histogram()
, making it simpler to obtain certain common
histogram adornments. This is done be resetting the default panel
and prepanel functions used by histogram.
xhistogram(...)xhistogramBreaks(x, center = NULL, width = NULL, nint, ...)
prepanel.xhistogram(x, breaks = xhistogramBreaks, ...)
panel.xhistogram(x, dcol = trellis.par.get("plot.line")$col, dalpha = 1,
dlwd = 2, gcol = trellis.par.get("add.line")$col, glwd = 2,
fcol = trellis.par.get("superpose.polygon")$col, dmath = dnorm,
verbose = FALSE, dn = 100, args = NULL, labels = FALSE,
density = NULL, under = FALSE, fit = NULL, start = NULL,
type = "density", v, h, groups = NULL, center = NULL, width = NULL,
breaks, nint = round(1.5 * log2(length(x)) + 1), stripes = c("vertical",
"horizontal", "none"), alpha = 1, ...)
additional arguments passed from lattice::histogram()
to the panel function; by default when the mosaic package has been loaded this will
panel.xhistogram()
.
a formula or a numeric vector
center of one of the bins
width of the bins
approximate number of bins
break points for histogram bins, a function for computing such,
or a method hist()
knows about given as a character string.
When using the mosaic package defaults,
mosaic::xhistogramBreaks()
is used.
color of density curve
alpha for density curve
like lwd
but affecting the density line and guide lines, respectively
color of guidelines
fill colors for histogram rectangles when using groups
.
(Use col
, which is passed through to panel.histogram(), when
not using groups
.
density function for density curve overlay
be verbose?
number of points to sample from density curve
a list of additional arguments for dmath
should counts/densities/precents be displayed or each bin?
a logical indicating whether to overlay a density curve
a logical indicating whether the density layers should be under or over other layers of the plot.
a character string describing the distribution to fit. Known distributions include
"exponential"
, "normal"
, "lognormal"
, "poisson"
, "beta"
, "geometric"
,
"t"
, "weibull"
, "cauchy"
, "gamma"
, "chisq"
, and "chi-squared"
numeric value passed to MASS::fitdistr()
one of 'density'
, 'count'
, or 'percent'
a vector of values for additional horizontal and vertical lines
as per lattice::histogram()
one of "vertical"
, "horizontal"
, or "none"
, indicating
how bins should be striped when groups
is not NULL
transparency level
a panel function
xhistogramBreaks
returns a vector of break points
The primary additional functionality added to histogram()
are the arguments width
and center
which provide a simple
way of describing equal-sized bins, and fit
which can be used to
overlay the density curve for one of several distributions. The
groups
argument can be used to color the bins. The primary use
for this is to shade tails of histograms, but there may be other uses
as well.
lattice::histogram()
, mosaicLatticeOptions()
,
and restoreLatticeOptions()
.
# NOT RUN {
if (require(mosaicData)) {
histogram(~age | substance, HELPrct, v=35, fit='normal')
histogram(~age, HELPrct, labels=TRUE, type='count')
histogram(~age, HELPrct, groups=cut(age, seq(10,80,by=10)))
histogram(~age, HELPrct, groups=sex, stripes='horizontal')
histogram(~racegrp, HELPrct, groups=substance,auto.key=TRUE)
xhistogramBreaks(1:10, center=5, width=1)
xhistogramBreaks(1:10, center=5, width=2)
xhistogramBreaks(0:10, center=15, width=3)
xhistogramBreaks(1:100, center=50, width=3)
xhistogramBreaks(0:10, center=5, nint=5)
}
# }
Run the code above in your browser using DataLab