addBars: Bar Graph

View source: R/addBars.R

addBarsR Documentation

Bar Graph

Description

Creates a bar chart by adding bars to an existing graph.

Usage

addBars(x, y, base = 0, Bars = list(name = "Auto", fill = "gray80",
  outline = "black", width = "Auto", orientation = "stack"),
  current = list(yaxis.log = FALSE, yaxis.rev = FALSE, xaxis.log =
  FALSE))

Arguments

x

the x-coordinate data. Missing values are permitted but result in no bar.

y

the heights of the bars or y-coordinate data. Missing values are permitted but result in no bar. For stacked or grouped bars, y must be a matrix, each row corresponding to the value in x and the columns representing each bar. See Note.

base

extend the bars from this value.

Bars

parameters defining the characteristics of the bars. See Details.

current

the current plot information. Typically, this would be the output from one of the graph creation functions like xyPlot. See Note.

Details

The Bars argument must be a tagged list with these components:

name

a character vector describing each column of data; used in the explanation. If "Auto," then derive the name from the column names in y.

fill

the name of the color to fill each bar. For multiple bars, can be a vector of colors or the name of a color sequence generating function, such as "pastel.colors."

outline

the name of the color to draw the outline or border for each bar. If "none," then no border is drawn.

width

the width of each bar in x-axis units. For discrete x-axis, If width 1, then the bars form a continuous filled area. The default is "Auto," which fills 2/3 of the distance. If 0, then draw vertical lines rather than bars; the color of the line is based on outline.

orientation

the orientation of the bars. Must be either "stack" or "group." Can be abbreviated to a single letter.

Value

The current plot information is returned invisibly.

Note

Use of addBars adds 1 step to creating bar charts, but adds flexibility in axis formatted from existing high-level plotting functions such as xyPlot or timePlot.

Bars are only valid for linear y-axes. Calling addBars when yaxis.log or yaxis.rev is TRUE or for any arbitrary transform of the y-axis will cause addBars to fail.

Datasets containing grouped data are often stacked with a column indicating the grouping. There are several functions that will reformat stacked datasets. The group2row function is very flexible in accepting many types of data to reformat rather than only numeric data.

See Also

xyPlot, timePlot, addXY group2row

Examples

## Not run: 
set.seed(1)
X <- seq(1, 9, by=1.0)
Y <- runif(9) + runif(9)
setGD()
AA.pl <- xyPlot(X, Y, Plot=list(what="none"), yaxis.range=c(0,2))
addBars(X, Y, base=0, current=AA.pl)
# For more details of addBars see
demo(topic="AnnualFlowBarChart", package="smwrGraphs")

## End(Not run)

USGS-R/smwrGraphs documentation built on Oct. 11, 2022, 6:11 a.m.