Learn R Programming

lattice (version 0.20-44)

B_02_barchart.table: table methods for barchart and dotplot

Description

Contingency tables are often displayed using bar charts and dot plots. These methods operate directly on tables, bypassing the need to convert them to data frames for use with the formula interface. Matrices and arrays are also supported, by coercing them to tables.

Usage

# S3 method for table
barchart(x, data, groups = TRUE,
         origin = 0, stack = TRUE, …, horizontal = TRUE)

# S3 method for array barchart(x, data, …)

# S3 method for matrix barchart(x, data, …)

# S3 method for table dotplot(x, data, groups = TRUE, …, horizontal = TRUE)

# S3 method for array dotplot(x, data, …)

# S3 method for matrix dotplot(x, data, …)

Arguments

x

A table, array or matrix object.

data

Should not be specified. If specified, will be ignored with a warning.

groups

A logical flag, indicating whether to use the last dimension as a grouping variable in the display.

origin, stack

Arguments to panel.barchart. The defaults for the table method are different.

horizontal

Logical flag, indicating whether the plot should be horizontal (with the categorical variable on the y-axis) or vertical.

Other arguments, passed to the underlying formula method.

Value

An object of class "trellis". The update method can be used to update components of the object and the print method (usually called by default) will plot it on an appropriate plotting device.

Details

The first dimension is used as the variable on the categorical axis. The last dimension is optionally used as a grouping variable (to produce stacked barcharts by default). All other dimensions are used as conditioning variables. The order of these variables cannot be altered (except by permuting the original argument beforehand using t or aperm). For more flexibility, use the formula method after converting the table to a data frame using the relevant as.data.frame method.

See Also

barchart, t, aperm, table, panel.barchart, Lattice

Examples

Run this code
# NOT RUN {
barchart(Titanic, scales = list(x = "free"),
         auto.key = list(title = "Survived"))
# }

Run the code above in your browser using DataLab