tallbar: Tall barplots

View source: R/plot2.R

tallbarR Documentation

Tall barplots

Description

Stack multiple bar plots vertically (or horizontally).

Usage

tallbar(height, labels = names(height), groups = NULL, horiz = TRUE, ...)

Arguments

height

a list of barplots having either a single row or a common row variable

labels, groups

labels for each bar plot in height and (optionally) for groups of bar plots

horiz

logical the direction of the bars

...

additional arguments passed to barplot2

Value

The default return of barplot2 plus additional elements names, labels, and groups giving the tick coordinates and labels for each, useful for finer control over the axes; see examples.

Examples

x <- mtcars[, sapply(mtcars, function(x) length(unique(x)) < 5)]
y <- sapply(x, simplify = FALSE, function(x) t(table(x, mtcars$mpg > 25)))
x <- sapply(x, simplify = FALSE, function(x) t(table(x)))

tallbar(x, horiz = FALSE)
tallbar(x, las = 1)
tallbar(x, las = 1, groups = c('Group 2' = 2, 'Group 3' = 4))

bp <- tallbar(
  y, horiz = TRUE, las = 1, axisnames = FALSE,
  groups = c('Group 2' = 2, 'Group 3' = 4)
)
axis(2, bp$names,  names(bp$names),  las = 1, lwd = 0)
axis(2, bp$labels, names(bp$labels), las = 1, lwd = 0, font = 3)
axis(2, bp$groups, names(bp$groups), las = 1, lwd = 0, font = 2)


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.