addPolygon: Add a polygon to an existing xts plot

View source: R/plot.R

addPolygonR Documentation

Add a polygon to an existing xts plot

Description

Draw a polygon on an existing xts plot by specifying a time series of y coordinates. The xts index is used for the x coordinates and the first two columns are the upper and lower y coordinates, respectively.

Usage

addPolygon(x, y = NULL, main = "", on = NA, col = NULL, ...)

Arguments

x

an xts object to plot. Must contain 2 columns for the upper and lower y coordinates for the polygon. The first column is interpreted as the upper y coordinates and the second column as the lower y coordinates.

y

NULL, not used

main

main title for a new panel if drawn.

on

panel number to draw on. A new panel will be drawn if on=NA.

col

color palette to use, set by default to rational choices.

...

passthru parameters to par

Author(s)

Ross Bennett

References

Based on code by Dirk Eddelbuettel from http://dirk.eddelbuettel.com/blog/2011/01/16/

Examples

## Not run: 
library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)[,1]
ix <- index(x["2007-02"])
shade <- xts(matrix(rep(range(x), each = length(ix)), ncol = 2), ix)

plot(x)

# set on = -1 to draw the shaded region *behind* the main series
addPolygon(shade, on = -1, col = "lightgrey")

## End(Not run)

joshuaulrich/xts documentation built on March 9, 2024, 2:50 a.m.