Learn R Programming

lattice (version 0.2-3)

histogram: Histograms

Description

Draw Histograms

Usage

histogram(formula,
          type = c("percent", "count", "density"),
          nint = if(is.factor(x)) length(levels(x))
                 else round(log2(length(x))+1),
          endpoints = range(x[!na.x]),
          breaks = if(is.factor(x)) seq(0.5, length = length(levels(x))
          + 1) else do.breaks(endpoints, nint),
          ...)

Arguments

formula
A formula of the form ~ x | g1 * g2 * ... indicates that histograms of x should be produced conditioned on the levels of the (optional) variables g1,g2,.... x can be numeric or factor, a
type
Character string indicating type of histogram to be drawn. "percent" and "count" give relative frequency and frequency histograms, and can be misleading when breakpoints are not equally spaced. "density" produces a density scale histogram. (Se
nint
Number of bins. Applies only when breaks is unspecified in the call.
endpoints
vector of length 2 indicating the range of x-values that is to be covered by the histogram. Again, applies only when breaks is unspecified.
breaks
numeric vector of length = (number of bins + 1) defining the breakpoints of the bins. Note that when breakpoints are not equally spaced, the only value of type that makes sense is density.

Usually all panels use the same brea

...
other arguments

Value

  • An object of class ``trellis'', plotted by default by print.trellis.

synopsis

histogram(formula, type = c("percent", "count", "density"), nint = if (is.factor(x)) length(levels(x)) else round(log2(length(x)) + 1), endpoints = range(x[!is.na(x)]), breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + 1) else do.breaks(endpoints, nint), aspect = "fill", as.table = FALSE, between = list(x = 0, y = 0), data, groups = NULL, key = NULL, layout, main = NULL, page = NULL, panel = panel.histogram, par.strip.text, prepanel, scales, skip = FALSE, strip = strip.default, sub = NULL, subscripts = !missing(groups), subset, xlab, xlim, ylab, ylim, ...)

Details

see the documentation for trellis.args.

See Also

trellis.args, panel.histogram, Lattice

Examples

Run this code
data(singer)
histogram( ~ height | voice.part, data = singer, nint = 17,
          endpoints = c(59.5, 76.5), layout = c(2,4), aspect = 1,
          xlab = "Height (inches)")
## The following would not be possible in S-Plus
histogram( ~ height | voice.part, data = singer,
          xlab = "Height (inches)", type = "density",
          panel = function(x, ...) {
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm,
                                args = list(mean=mean(x),sd=sd(x)))
          } )

Run the code above in your browser using DataLab