Rev 437 | Blame | Last modification | View Log | Download | RSS feed
\name{barplot}\title{Bar Plots}\usage{barplot(height, width = 1, space = NULL, names.arg = NULL,legend.text = NULL, beside = FALSE, horiz = FALSE,col = heat.colors(NR), border = par("fg"), main = NULL,xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL,axes = TRUE, ...)}\alias{barplot}\arguments{\item{height}{either a vector or matrix of values describing the barswhich make up the plot. If \code{height} is a vector, the plotconsists of a sequence of rectangular bars with heights given by thevalues in the vector. If \code{height} is a matrix and\code{beside} is \code{FALSE} then each bar of the plot correspondsto a column of \code{height}, with the values in the column givingthe heights of stacked ``sub-bars'' making up the bar. If\code{height} is a matrix and \code{beside} is \code{TRUE}, then thevalues in each column are juxtaposed rather than stacked.}\item{width}{optional vector of bar widths.}\item{space}{the amount of space (as a fraction of the average barwidth) left before each bar. May be given as a single number or onenumber per bar. If \code{height} is a matrix and \code{beside} is\code{TRUE}, \code{space} may be specified by two numbers, where thefirst is the space between bars in the same group, and the secondthe space between the groups. If not given explicitly, it defaultsto \code{c(0,1)} if \code{height} is a matrix and \code{beside} is\code{TRUE}, and to 0.2 otherwise.}\item{names.arg}{a vector of names to be plotted below each bar orgroup of bars. If this argument is omitted, then the names aretaken from the \code{names} attribute of \code{height} if this is avector, or the column names of \code{height} if this is a matrix.}\item{legend.text}{a vector of text used to construct a legend for theplot. This is only useful when \code{height} is a matrix. In thatcase the legend labels should correspond to the rows of\code{height}.}\item{beside}{a logical value. If \code{FALSE}, the columns of\code{height} are portrayed as stacked bars, and if \code{TRUE} thecolumns are portrayed as juxtaposed bars.}\item{horiz}{a logical value. If \code{FALSE}, the bars are drawnvertically with the first bar to the left. If \code{TRUE}, the barsare drwan horizontally with the first at the bottom.}\item{col}{a vector of colors for the bars or bar components.}\item{border}{the color to be used for the border of the bars.}\item{main}{an overall title for the plot.}\item{xlab}{a label for the x axis.}\item{ylab}{a label for the y axis.}\item{xlim}{limits for the x axis.}\item{ylim}{limits for the y axis.}\item{axes}{logical. If \code{TRUE}, a vertical axis is drawn.}\item{\dots}{further arguments are passed to \code{title(.)}.}}\value{A numeric vector, giving the coordinates of the bar midpoints drawn,useful for adding to the graph.}\seealso{\code{\link{plot}(\dots,type="h")},\code{\link{dotplot}}, \code{\link{hist}}.}\examples{tN <- table(Ni <- rpois(100, lambda=5))r <- barplot(tN, col='gray')points(r, tN, type='h', col='red', lwd=2)#- type = "h" plotting *is* `bar'plotdata(deaths, package = "base")mp <- barplot(deaths) # defaulttot <- apply(deaths,2,sum); text(mp, tot + 3, format(tot))barplot(deaths, beside = TRUE,col = c("lightblue", "mistyrose", "lightcyan","lavender", "cornsilk"),legend = rownames(deaths), ylim = c(0, 100))title(main = "Death Rates in Virginia", font.main = 4)barplot(t(deaths)[, 5:1], beside = TRUE,col = c("lightblue", "mistyrose","lightcyan", "lavender"),legend = colnames(deaths), ylim = c(0,80),main = "Death Rates in Virginia", font.main = 4)## instead of title(.)}\keyword{hplot}