Description Usage Arguments Details Value Author(s) See Also Examples
This function creates a bar plot based on a categorical variable to show the
counts of all categories. Another categorical variable can be used to further
split each bar into sub-categories, which will make the bar plot a
representation of a contingency table. The splitting variable can be
specified in qdata
using either the color
argument or
the border
argument.
1 2 |
x |
a variable name (will be coerced to a factor if it is not; |
data |
a mutaframe created by |
weight |
weight the bars by the sums of another variable instead of the
counts of |
space |
the space between bars proportional to the width of bars |
main |
the main title |
horizontal |
|
standardize |
logical: whether to standardize the height of each bar to 1 |
xlim |
a numeric vector of length 2 (like |
ylim |
y-axis limits; similar to |
xlab |
x-axis title |
ylab |
y-axis title |
All the common interactions like brushing and deleting are documented in
common_key_press
.
In the identify mode (press the key ?
to toggle between brush and
identify mode), the variable and its identified values are shown as a text
label in the plot, along with the counts and proportion of the identified
categories. If the bar plot is split by an additional categorical variable,
it will also be shown in the label.
A zero-count category is represented by a one-pixel rectangle, which is a useful visual hint to indicate the presence of this category.
The x-axis (or y-axis when horizontal = TRUE
) tickmark locations are
from 1 to n
shifted to the right by 0.5 (i.e. 1.5, 2.5, ...), where
n
is the number of levels of the factor variable to be plotted.
A bar plot
Yihui Xie <http://yihui.name>
Other plots: qboxplot
;
qdensity
; qhist
,
qspine
; qmval
;
qparallel
; qtime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | library(cranvas)
## tennis data
qtennis <- qdata(tennis)
qbar(matches, data = qtennis)
qbar(matches, data = qtennis, weight = serve.speed)
## NRC rankings
qnrc <- qdata(nrcstat, color = Control) # Control: public or private univ
qbar(RegCode, data = qnrc, main = "Number of public and private colleges in each region")
qparallel(vars = 13:10, data = qnrc, main = "Overview of Rankings", glyph = "tick",
horizontal = TRUE, boxplot = TRUE)
qbar(RegCode, data = qnrc, horizontal = TRUE) # horizontal plot
qbar(RegCode, data = qnrc, standardize = TRUE) # standardize to 1
## use border color to split the bars
qnrc2 <- qdata(nrcstat, color = "white", border = Control)
qbar(RegCode, data = qnrc2)
## happy data
library(productplots)
qhappy <- qdata(happy, color = happy)
qbar(happy, data = qhappy)
cranvas_off()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.