propfall | R Documentation |
A barplot of proportions.
propfall(data, group, order, group.order = unique(group), col = NULL, ...)
data |
a data frame (or object to be coerced) |
group |
a vector with length |
order |
a vector of column names of |
group.order |
an optional vector of unique values of |
col |
a vector of colors for each of |
... |
additional parameters passed to |
A list of length two with the result of the call to barplot
(bp
) giving the x-axis positions for each bar and the o
rder
that each observation has been sorted in the barplot.
waterfall
dat <- within(mtcars, {
disp <- disp / 10
wt <- wt * 10
})
vars <- c('mpg', 'disp', 'wt')
dat[, vars] <- t(apply(dat[, vars], 1L, function(x) x / sum(x)))
dat <- dat[, vars]
dat$group <- colnames(dat)[max.col(dat)]
cols <- c('grey', 'lightpink', 'indianred1')
propfall(dat[, 1:3])
propfall(dat[, 1:3], group = dat$group, col = cols)
## use the return value to add labels or identify observations
bp <- propfall(
dat[, 1:3], col = cols, group = dat$group,
order = c('disp', 'wt', 'mpg'),
group.order = c('mpg', 'wt', 'disp')
)
text(bp$bp, 0, labels = rownames(dat)[bp$o], srt = 90, col = 0, adj = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.