Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

barlabels

Label the bars on a barplot


Description

Displays labels on a plot, usually a bar plot.

Usage

barlabels(xpos,ypos,labels=NULL,cex=1,prop=0.5,miny=0,offset=0,nobox=FALSE,...)

Arguments

xpos

A vector, matrix or data frame of x positions for the labels.

ypos

A vector, matrix or data frame of y values for the labels.

labels

The labels to display. Defaults to the values of ypos.

cex

Relative size of the labels. See text.

prop

The proportion of ypos at which to place the labels. Defaults to 0.5 (the middle).

miny

The minimum value at which to display labels.

offset

Amount to horizontally offset successive labels in case of vertical overlaps.

nobox

Whether to call sampboxed.labels or text.

...

Extra arguments passed to boxed.labels or text.

Details

barlabels places labels on a plot at horizontal positions xpos and vertical positions ypos * prop. The typical use of this function is to place labels on bars, by default in the middle of the bars.

To put labels just over the tops of the bars, set prop to 1 and add a constant amount to ypos.

Value

nil

Author(s)

Jim Lemon

See Also

Examples

heights<-c(14,20,9,31,17)
 barpos<-barplot(heights,main="A redundant bar plot")
 # show the usual value labels on the bars
 barlabels(barpos,heights)
 # now with stacked bars and offsets
 heights<-matrix(sample(c(1,2,10,15),20,TRUE),ncol=4)
 barpos<-barplot(heights,main="A redundant stacked bar plot")
 barlabels(barpos,heights,offset=0.1)
 # do it again without stacking
 barpos<-barplot(heights,main="An unstacked redundant bar plot",
  beside=TRUE)
 barlabels(barpos,heights)
 # finally use barp for the plot
 barpos<-barp(heights,main="A fourth and final bar plot",col=2:6,
  names.arg=paste("Day",1:4))
 barlabels(barpos$x,barpos$y,matrix(LETTERS[1:5],nrow=5,ncol=4))

plotrix

Various Plotting Functions

v3.8-1
GPL (>= 2)
Authors
Jim Lemon, Ben Bolker, Sander Oom, Eduardo Klein, Barry Rowlingson, Hadley Wickham, Anupam Tyagi, Olivier Eterradossi, Gabor Grothendieck, Michael Toews, John Kane, Rolf Turner, Carl Witthoft, Julian Stander, Thomas Petzoldt, Remko Duursma, Elisa Biancotto, Ofir Levy, Christophe Dutang, Peter Solymos, Robby Engelmann, Michael Hecker, Felix Steinbeck, Hans Borchers, Henrik Singmann, Ted Toal, Derek Ogle, Darshan Baral, Ulrike Groemping, Bill Venables
Initial release
2021-01-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.