This creates a stacked column chart with time on the horizontal axis and values in categories. This kind of chart is commonly used for showing portfolio 'weights' through time, although the function will plot any values by category.
chart.StackedBar(
w,
colorset = NULL,
space = 0.2,
cex.axis = 0.8,
cex.legend = 0.8,
cex.lab = 1,
cex.labels = 0.8,
cex.main = 1,
xaxis = TRUE,
legend.loc = "under",
element.color = "darkgray",
unstacked = TRUE,
xlab = "Date",
ylab = "Value",
ylim = NULL,
date.format = "%b %y",
major.ticks = "auto",
minor.ticks = TRUE,
las = 0,
xaxis.labels = NULL,
...
)
a matrix, data frame or zoo object of values to be plotted. Rownames should contain dates or period labels; column names should indicate categories. See examples for detail.
color palette to use, set by default to rational choices
the amount of space (as a fraction of the average bar width)
left before each bar, as in barplot
. Default is 0.2.
The magnification to be used for sizing the axis text
relative to the current setting of 'cex', similar to plot
.
The magnification to be used for sizing the legend
relative to the current setting of 'cex', similar to plot
.
The magnification to be used for x- and y-axis labels relative to the current setting of 'cex'.
The magnification to be used for event line labels relative to the current setting of 'cex'.
The magnification to be used for the chart title relative to the current setting of 'cex'.
If true, draws the x axis
places a legend into a location on the chart similar to
chart.TimeSeries
. The default, "under," is the only location
currently implemented for this chart. Use 'NULL' to remove the legend.
provides the color for drawing less-important chart elements, such as the box lines, axis lines, etc.
logical. If set to 'TRUE' and only one row of data is submitted in 'w', then the chart creates a normal column chart. If more than one row is submitted, then this is ignored. See examples below.
the x-axis label, which defaults to 'NULL'.
Set the y-axis label, same as in plot
set the y-axis limit, same as in plot
Re-format the dates for the xaxis; the default is "%m/%y"
Should major tickmarks be drawn and labeled, default 'auto'
Should minor tickmarks be drawn, default TRUE
sets the orientation of the axis labels, as described in
par
. Defaults to '3'.
Allows for non-date labeling of date axes, default is NULL
arguments to be passed to barplot
.
This function is a wrapper for barplot
but adds three
additional capabilities. First, it calculates and sets a bottom margin for
long column names that are rotated vertically. That doesn't always result
in the prettiest chart, but it does ensure readable labels.
Second, it places a legend "under" the graph rather than within the bounds of the chart (which would obscure the data). The legend is created from the column names. The default is to create the legend when there's more than one row of data being presented. If there is one row of data, the chart may be "unstacked" and the legend removed.
Third, it plots or stacks negative values from an origin of zero, similar to
the behavior of barchart
from the 'lattice' package.
Cleveland, W.S. (1994), The Elements of Graphing Data, Summit, NJ: Hobart Press.
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, 2nd edition. The Graphics Press, Cheshire, Connecticut. See http://www.edwardtufte.com for this and other references.
# NOT RUN {
data(weights)
head(weights)
# With the legend "under" the chart
chart.StackedBar(weights, date.format="%Y", cex.legend = 0.7, colorset=rainbow12equal)
# Without the legend
chart.StackedBar(weights, colorset=rainbow12equal, legend.loc=NULL)
# for one row of data, use 'unstacked' for a better chart
chart.StackedBar(weights[1,,drop=FALSE], unstacked=TRUE, las=3)
# }
Run the code above in your browser using DataLab