propfall: propfall

Description Usage Arguments Value See Also Examples

View source: R/plot_misc.R

Description

A barplot of proportions.

Usage

1
propfall(data, group, order, group.order = unique(group), col = NULL, ...)

Arguments

data

a data frame (or object to be coerced)

group

a vector with length nrow(data) defining the group to which each row of data belongs

order

a vector of column names of data defining how numeric values should be sorted

group.order

an optional vector of unique values of group giving the desired order for groups

col

a vector of colors for each of order, recycled as needed

...

additional parameters passed to barplot or graphical parameters passed to par

Value

A list of length two with the result of the call to barplot (bp) giving the x-axis positions for each bar and the order that each observation has been sorted in the barplot.

See Also

waterfall

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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', 'indianred3')
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)

raredd/plotr documentation built on Nov. 19, 2018, 11:02 a.m.