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.
"barchart"(x, data, groups = TRUE, origin = 0, stack = TRUE, ..., horizontal = TRUE)
"barchart"(x, data, ...)
"barchart"(x, data, ...)
"dotplot"(x, data, groups = TRUE, ..., horizontal = TRUE)
"dotplot"(x, data, ...)
"dotplot"(x, data, ...)
table
, array
or matrix
object.
panel.barchart
. The defaults for the
table
method are different.
formula
method.
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.
barchart(Titanic, scales = list(x = "free"),
auto.key = list(title = "Survived"))
Run the code above in your browser using DataLab