addBars | R Documentation |
Creates a bar chart by adding bars to an existing graph.
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))
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, |
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 |
The Bars
argument must be a tagged list with these components:
a character vector describing each column of data; used in the
explanation. If "Auto," then derive the name from the column names in y
.
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."
the name of the color to draw the outline or border for each bar. If "none," then no border is drawn.
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
.
the orientation of the bars. Must be either "stack" or "group." Can be abbreviated to a single letter.
The current plot information is returned invisibly.
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.
xyPlot
, timePlot
, addXY
group2row
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.