barlabel: Bar plot labels

View source: R/plot_extra.R

barlabelR Documentation

Bar plot labels

Description

Add labels to a barplot.

Usage

barlabel(
  x,
  labels = x,
  at = barplot(x, plot = FALSE, horiz = horiz, beside = beside),
  horiz = FALSE,
  beside = FALSE,
  hadj = 0,
  vadj = 0,
  position = c("middle", "top", "bottom"),
  plot = TRUE,
  ...
)

Arguments

x

a vector or matrix of bar heights, typically the same object used in barplot(x)

labels

labels for each bar segment

at

the position of the midpoint of each bar

horiz

logical; plot vertical (default) or horizontal bars

hadj, vadj

optional horizontal and vertical adjustments to the calculated coordinates

position

the position for labels relative to each bar segment, one of "middle" (default), "top", or "bottom"

plot

logical; if TRUE, labels are drawn; otherwise, calculated coordinates are returned invisibly

...

additional graphical parameters passed to text or further to par

Value

A list containing the x- and y-coordinates at which labels were drawn.

Examples

x <- table(mtcars$gear)
barplot(x)
barlabel(x, position = 'top', pos = 3L)

x <- table(mtcars$gear, mtcars$vs)
barplot(x)
barlabel(x, labels = sprintf('n = %s (%.1f%%)', x, x / colSums(x) * 109),
         col = cm.colors(nrow(x)))

bp <- barplot(x, beside = TRUE)
barlabel(x, beside = TRUE)


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