Create a bar chart of a single categorical variable or a grouped bar chart of two categorical variables.
groupedBar(resp, ...)# S3 method for default
groupedBar(resp, condvar = NULL, percent = TRUE,
print = TRUE, cond.name = deparse(substitute(condvar)),
resp.name = deparse(substitute(resp)), ...)
# S3 method for formula
groupedBar(formula, data = parent.frame(), subset, ...)
Returns invisibly a table of the variable(s).
a factor variable. If resp
is numeric, it will be coerced to a
factor variable.
further arguments to be passed to or from methods.
a factor variable to condition on. If NULL
, then a bar
plot of just the resp
variable will be created. If condvar
is
numeric, it will be coerced to a factor variable.
a logical value. Should the y-axis give percent or counts?
a logical value. If TRUE
, print out the table.
Label for variable condvar
.
Label for variable resp
.
a formula of the form x ~ condvar
. If x
or
condvar
is (are) not a factor variable, then it (they) will be
coerced into one. Formula can also be ~ x
for a single factor variable.
a data frame that contains the variables in the formula.
an optional vector specifying a subset of observations to be used.
default
: Grouped bar chart
formula
: Grouped bar chart
Laura Chihara
For a single factor variable, a bar plot. If two factor variables are given,
then a bar plot of x
conditioned by condvar
. This command
uses R's table
command so missing values are automatically removed.
groupedBar(states03$Region)
groupedBar(states03$DeathPenalty, states03$Region, legend.loc = "topleft")
#Using a formula syntax:
groupedBar(~Region, data = states03)
groupedBar(DeathPenalty ~ Region, data = states03, legend.loc = "topleft")
Run the code above in your browser using DataLab