Plot Multiple Time Series

DESCRIPTION:
Plots one or more time series on the current graphics device. By default, five line types and four colors (if available) are cycled through.

USAGE:
tsplot(..., type="l", lty=1:5, pch=<<see below>>, col=1:4)
tspoints(..., type="p", lty=1:5, pch=<<see below>>, col=1:4)
tslines(..., type="l", lty=1:5, pch=<<see below>>, col=1:4)

REQUIRED ARGUMENTS:
...:
any number of univariate or multivariate time series to be plotted. The x-axis is set up as the union of the times spanned by the series. The y-axis includes the range of all the series.
Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:
type=:
character string with letters from {p, l, b, o, n, h}, telling which type of plot (points, lines, both, overlaid, none or high-density) should be done for each plot. The first character of type defines the first plot, the second character the second, etc. Characters in type are used cyclically; e.g., "pl" alternately plots points and lines.
lty=:
vector of line types. The first element is the line type for the first line, etc. Line types will be used cyclically until all plots are drawn.
pch=:
character string or integer vector of plotting characters. The first character is the plotting character for the first plot of type "p", the second for the second, etc. The default is the digits (1 through 9, 0) then the lower case letters. To mix special plotting symbols (those specified by integers) and plotting characters, either use character escapes pch="X\002" or figure out the numeric equivalent of the ASCII character, pch=c(88,2).
col=:
vector of colors. Colors are also used cyclically.

Graphical parameters may also be supplied as arguments to this function (see par). In addition, the high-level graphics arguments described under par and the arguments to title may be supplied to this function.


SIDE EFFECTS:
tsplot generates a new plot; tspoints and tslines add to the current plot.

DETAILS:
Missing values are not plotted and lines that have an endpoint that is missing are not drawn.

Note that all series are assumed to be in the same units.

Because plotting symbols are drawn with lines and because these functions may be changing the line style, you should probably specify lty=1 when using plotting symbols.


BUGS:
The commands xaxs="d" and yaxs="d" must be specified in a call to par rather than as arguments to tsplot. Remember to release the direct axis afterwards.

NOTE:
Time series created by ts have been superseded by the classed time series created by rts, cts, and its. You can coerce a old-style time series to a new with as.rts. The new plotting functions for time series are ts.plot, ts.lines and ts.points.

SEE ALSO:
plot , par , title .

EXAMPLES:
tsplot(gnp, smooth(gnp), type="pl")
tspoints(x, y, pch="*") # points with "*" for both series
tsplot(hstart, smooth(hstart), type="pl")
title(main="Housing Starts", sub="Data and Smoothed Values")

sun.agg <- aggregate(sunspots, 1, "mean") par(mar=rep(5, 4)) tsplot(rain.nyc2, ylab="rain in inches") legend(1910, 57, c("rain", "sunspots"), lty=1:2) par(new=T) # trick to add plot with different scale tsplot(window(sun.agg, start(rain.nyc2), end(rain.nyc2)), axes=F, lty=2) axis(4) mtext("mean number of sunspots", side=4, line=3) title(main="New York Rainfall and Sunspot Activity")