Description Usage Arguments Details Value Note See Also Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14  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 
x 
a formula or a numeric vector 
center 
center of one of the bins 
width 
width of the bins 
nint 
approximate number of bins 
breaks 
break points for histogram bins, a function for computing such,
or a method 
dcol 
color of density curve 
dalpha 
alpha for density curve 
dlwd, glwd 
like 
gcol 
color of guidelines 
fcol 
fill colors for histogram rectangles when using 
dmath 
density function for density curve overlay 
verbose 
be verbose? 
dn 
number of points to sample from density curve 
args 
a list of additional arguments for 
labels 
should counts/densities/precents be displayed or each bin? 
density 
a logical indicating whether to overlay a density curve 
under 
a logical indicating whether the density layers should be under or over other layers of the plot. 
fit 
a character string describing the distribution to fit. Known distributions include

start 
numeric value passed to 
type 
one of 
h, v 
a vector of values for additional horizontal and vertical lines 
groups 
as per 
stripes 
one of 
alpha 
transparency level 
panel 
a panel function 
The primary additional functionality added to histogram()
are the arguments width
and center
which provide a simple
way of describing equalsized 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.
xhistogramBreaks
returns a vector of break points
Versions of lattice since 0.2021 support setting custom defaults
for breaks
, panel
, and prepanel
used by
histogram()
, so xhistogram()
is no longer needed.
As a result, xhistogram()
(which was required in earlier versions of mosaic
is no longer needed and has been removed.
lattice::histogram()
, mosaicLatticeOptions()
,
and restoreLatticeOptions()
.
1 2 3 4 5 6 7 8 9 10 11 12  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)
}

Loading required package: dplyr
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Loading required package: lattice
Loading required package: ggformula
Loading required package: ggplot2
New to ggformula? Try the tutorials:
learnr::run_tutorial("introduction", package = "ggformula")
learnr::run_tutorial("refining", package = "ggformula")
Loading required package: mosaicData
Loading required package: Matrix
The 'mosaic' package masks several functions from core packages in order to add
additional features. The original behavior of these functions should not be affected by this.
Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
Attaching package: 'mosaic'
The following object is masked from 'package:Matrix':
mean
The following objects are masked from 'package:dplyr':
count, do, tally
The following objects are masked from 'package:stats':
IQR, binom.test, cor, cor.test, cov, fivenum, median, prop.test,
quantile, sd, t.test, var
The following objects are masked from 'package:base':
max, mean, min, prod, range, sample, sum
[1] 1.25 1.25 3.75 6.25 8.75 11.25
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.