barplot.xts: Time-Oriented Barplots from xts Objects

Description Usage Arguments Details Value Author(s) Examples

Description

A barplot method for xts objects.

Usage

1
2
3
4
5
6
7
## S3 method for class 'xts'
barplot(height, stacked = TRUE, scale = FALSE, auto.legend = TRUE, 
                        major.format = TRUE, ylim=NULL, space = 0.2, cex.axis=0.8,
                        cex.legend = 0.8, cex.lab = 1, cex.labels = 0.8, cex.main = 1,
                        xaxis=TRUE, box.color = "black", xlab="Date",
                        ylab="Value", major.ticks='auto', minor.ticks=TRUE,
                        xaxis.labels = NULL, col, ...)

Arguments

height

An xts object of desired frequency. Use to.period functions to aggregate data outside of barplot.

stacked

logical. Should barplot be stacked?

scale

logical. Should data be rescaled to sum to 100% at each bar? Currently does not support negative values.

auto.legend

logical. Should a legend be placed underneath the barplot?

major.format

Format string for x-axis time labels. If TRUE, automatically chosen

ylim

Limits of y-axis. If NULL, sensible defaults are chosen.

space

the amount of space (as a fraction of the average bar width) left before each bar, as in barplot. Default is 0.2.

cex.axis

The magnification to be used for sizing the axis text relative to the current setting of 'cex', similar to plot.

cex.legend

The magnification to be used for sizing the legend relative to the current setting of 'cex', similar to plot.

cex.labels

The magnification to be used for event line labels relative to the current setting of 'cex'.

cex.lab

The magnification to be used for x- and y-axis labels relative to the current setting of 'cex'.

cex.main

The magnification to be used for the chart title relative to the current setting of 'cex'.

xaxis

If true, draws the x axis

box.color

provides the color for drawing less-important chart elements, such as the box lines, axis lines, etc.

xlab

the x-axis label, which defaults to NULL.

ylab

Set the y-axis label, same as in plot

major.ticks

Should major tickmarks be drawn and labeled? Default 'auto'

minor.ticks

Should minor tickmarks be drawn? default TRUE

xaxis.labels

Allows for non-date labeling of date axes, default is NULL

col

Color of the bars. If missing, defaults to the somewhat garish colors provided by palette.

...

additional graphical arguments passed to barplot.

Details

Used to provide time-oriented barplots.

Value

Invisibly returns the plotted object. Also assigns .barplot.xts to .GlobalEnv which can be used to "replay" the plot.

Author(s)

Peter Carl with modifications by Michael Weylandt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
weights <- xts(matrix(runif(42, 0.1, 0.3), ncol = 6), as.yearmon(Sys.Date()) + 0:6)
names(weights) <- paste("Factor", LETTERS[1:6])

barplot(weights)

# No legend
barplot(weights, auto.legend = FALSE)

# Not Stacked
barplot(weights, stacked = FALSE)

# Scale weights to sum to 1
barplot(weights, scale = TRUE)

# A nicer color pallette
# rainbow6equal from Performance Analytics
barplot(weights, scale = TRUE, col = c("#BF4D4D", "#BFBF4D", "#4DBF4D", "#4DBFBF","#4D4DBF", "#BF4DBF"))

# Include negative data
weights[,3] <- weights[,3] * -1

barplot(weights)

barplot(weights, stacked = FALSE)

xtsExtra documentation built on April 15, 2017, 11 a.m.