Barplot | R Documentation |
Create bar plots for one or two factors scaled by frequency or precentages.
In the case of two factors, the bars can be divided (stacked) or plotted in
parallel (side-by-side). This function is a front end to barplot
in the graphics package.
Barplot(x, by, scale = c("frequency", "percent"), conditional=TRUE,
style = c("divided", "parallel"),
col=if (missing(by)) "gray" else rainbow_hcl(length(levels(by))),
xlab = deparse(substitute(x)), legend.title = deparse(substitute(by)),
ylab = scale, main=NULL, legend.pos = "above", label.bars=FALSE, ...)
x |
a factor (or character or logical variable). |
by |
optionally, a second factor (or character or logical variable). |
scale |
either |
conditional |
if |
style |
for two-factor plots, either |
col |
if |
xlab |
an optional character string providing a label for the horizontal axis. |
legend.title |
an optional character string providing a title for the legend. |
ylab |
an optional character string providing a label for the vertical axis. |
main |
an optional main title for the plot. |
legend.pos |
position of the legend, in a form acceptable to the |
label.bars |
if |
... |
arguments to be passed to the |
Invisibly returns the horizontal coordinates of the centers of the bars.
John Fox jfox@mcmaster.ca
barplot
, legend
, rainbow_hcl
with(Mroz, {
Barplot(wc)
Barplot(wc, col="lightblue", label.bars=TRUE)
Barplot(wc, by=hc)
Barplot(wc, by=hc, scale="percent", label.bars=TRUE)
Barplot(wc, by=hc, style="parallel",
scale="percent", legend.pos="center")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.