Learn R Programming

mosaic (version 0.4-1)

bargraph: Create bar graphs from raw data

Description

barchart from the lattice package makes bar graphs from pre-tabulated data. Raw data can be tabulated using xtabs, but the syntax is unusual compared to the other lattice plotting functions. bargraph provides an interface that is consistent with the other lattice functions.

Usage

bargraph(x, data = parent.frame(), groups,
    horizontal = FALSE, origin = 0, ylab = "Frequency",
    ...)

Arguments

x
a formula describing the plot
data
a data frame in which the formula x is evaluated
groups
a variable or expression used for grouping. See barchart.
horizontal
a logical indicating whether bars should be horizontal
...
additional arguments passed to barchart
origin
beginning point for bars. For the default behavior used by barchart set origin to NULL, but 0 is often a better default. If 0 is not good, perhaps you should use a
ylab
a character of length one used for the y-axis label

Value

  • a trellis object describing the plot

See Also

barchart

Examples

Run this code
data(HELPrct)
bargraph( ~ substance, data=HELPrct)
bargraph( ~ substance, data=HELPrct, horizontal=TRUE)
bargraph( ~ substance | sex, groups=homeless, auto.key=TRUE, data=HELPrct)

Run the code above in your browser using DataLab