Learn R Programming

lattice (version 0.3-1)

histogram: Histograms

Description

Draw Histograms

Usage

histogram(formula,
          data, 
          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),
          equal.widths = FALSE, 
          ...)

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
data
data frame in which variables are to be evaluated
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

equal.widths
logical, relevant only when breaks=NULL. If TRUE, equally spaced bins will be selected, otherwise, approximately equal area bins will be selected (this would mean that the breakpoints will not be equally space
...
other arguments

Value

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

synopsis

histogram(formula, data = parent.frame(), aspect = "fill", layout = NULL, panel = panel.histogram, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, type = c("percent", "count", "density"), nint, endpoints = range(x[!is.na(x)]), breaks, equal.widths = TRUE, ..., subscripts = !is.null(groups), subset = TRUE)

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