Learn R Programming

mosaic (version 0.4-1)

xhistogram: Augmented histograms

Description

xhistogram adds some additional functionality to histogram making it simpler to obtain certain common histogram adornments.

Usage

xhistogram(x, data = NULL, panel = panel.xhistogram,
    type = "density", center = NULL, width = NULL, breaks,
    nint, ...)

xhistogramBreaks(x, center = NULL, width = NULL, nint)

panel.xhistogram(x, dcol = trellis.par.get("plot.line")$col, 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 = 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, ...)

Arguments

x
a formula or a numeric vector
data
a data frame in which to evaluate x
panel
a panel function
type
one of 'density', 'count', or 'percent'
nint
approximate number of bins
breaks
break points for histogram bins, a function for computing such, or a method hist knows about given as a character string. If missing, xhistogramBreak
...
additional arguments passed to histogram and on to panel.xhistogram
dcol
color of density curve
gcol
color of guidelines
fcol
fill color for histogram rectangles
dmath
density function for density curve overlay
verbose
be verbose?
dn
number of points to sample from density curve
dlwd,glwd
like lwd but affecting the density line and guide lines, respectively
args
a list of additional arguments for dmath
labels
should counts/densities/precents be displayed or each bin?
density
overlay density?
fit
a character string describing the distribution to fit. Known distributions include "exponential", "normal", "lognormal", "poisson", "beta", "geometric", "t",
start
numeric value passed to fitdistr
center
center of one of the bins
width
width of the bins
groups
as per histogram
stripes
one of "vertical", "horizontal", or "none", indicating how bins should be striped when groups is not NULL
h,v
a vector of values for additional horizontal and vertical lines
alpha
transparency level

Value

  • a trellis object

    xhistogramBreaks returns a vector of break points

Examples

Run this code
xhistogram(~age | substance, HELPrct, v=35, fit='normal')
xhistogram(~age, HELPrct, labels=TRUE, type='count')
xhistogram(~age, HELPrct, groups=cut(age, seq(10,80,by=10)))
xhistogram(~age, HELPrct, groups=sex, stripes='horizontal')
xhistogram(~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