barprop | R Documentation |
A barplot
for proportions. This function is intended to show
a matrix of proportions as a stacked bar plot but each group will have a
common starting height. Therefore, it is recommended that each column sums
to 100
barprop(
height,
col = NULL,
labels = height,
col.labels = par("col.lab"),
horiz = TRUE,
gap = NULL,
min.prop = Inf,
axis.pos = NULL,
xlab = NULL,
ylab = NULL,
...
)
height |
a matrix (or vector) of proportions |
col |
colors for each group, i.e., |
labels |
a matrix or vector of labels for each bar plot segment; if
|
col.labels |
a matrix or vector of colors for each label, i.e.,
|
horiz |
logical; if |
gap |
the space between each group as a single value or vector in units
of |
min.prop |
the minimum proportion controlling which labels are drawn
in the center of each bar; for any |
axis.pos |
a vector of length 2 giving the position of the x- and
y-axes; note that |
xlab, ylab |
the x- and y-axis labels, default is
|
... |
additional graphical parameters passed to
the axis labels (i.e., the labels for each group) may be customized
using the main labels (i.e., |
x <- table(Gear = mtcars$gear, Cylinder = mtcars$cyl)
dimnames(x) <- lapply(dimnames(x), function(y) rawr::num2char(as.numeric(y)))
p <- round(prop.table(x, 2) * 100)
barprop(p)
barprop(x, horiz = FALSE)
## compare
barplot(x)
## on vectors (or single-column matrices)
barprop(p[, 1])
barprop(p[, 1, drop = FALSE])
## options/aesthetics
barprop(p, min.prop = 0, col.labels = ifelse(row(p) == 1, 'white', 'black'))
barprop(p, gap = 10)
barprop(p, min.prop = 0, gap = c(10, 0))
barprop(x, min.prop = 0, labels = sprintf('%s%%', x), cex.lab = 1.5,
font.axis = 2, cex.axis = 1.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.