Learn R Programming

oce (version 0.9-20)

oce.plot.ts: Oce Variant of plot.ts

Description

Plot a time-series, obeying the timezone and possibly drawing the range in the top-left margin.

Usage

oce.plot.ts(x, y, type = "l", xlim, ylim, xlab, ylab, drawTimeRange = getOption("oceDrawTimeRange"), adorn = NULL, fill = FALSE, xaxs = par("xaxs"), yaxs = par("yaxs"), cex = par("cex"), cex.axis = par("cex.axis"), cex.main = par("cex.main"), mgp = getOption("oceMgp"), mar = c(mgp[1] + if (nchar(xlab) > 0) 1.5 else 1, mgp[1] + 1.5, mgp[2] + 1, mgp[2] + 3/4), main = "", despike = FALSE, axes = TRUE, tformat, marginsAsImage = FALSE, grid = FALSE, grid.col = "darkgray", grid.lty = "dotted", grid.lwd = 1, debug = getOption("oceDebug"), ...)

Arguments

x
the times of observations.
y
the observations.
type
plot type, "l" for lines, "p" for points.
xlim
optional limit for x axis. This has an additional effect, beyond that for conventional R functions: it effectively windows the data, so that autoscaling will yield limits for y that make sense within the window.
ylim
optional limit for y axis.
xlab
name for x axis; defaults to "".
ylab
name for y axis; defaults to the plotted item.
drawTimeRange
a boolean, set to TRUE to indicate the range of times in the top-left margin.
adorn
(Defunct) An expression or vector of expressions that contain R code that is to be executed immediately after each panel of the plot. If the number of expressions matches the number of panels, then the expressions are used for the corresponding panels; otherwise, the expression list is extended to match the number of panels (i.e. to obtain length(which) elements). Note that adorn is a dangerous argument, because if the expressions contained therein set up local storage, there is a chance of entirely disrupting the plotting. For this reason, adorn was marked as defunct in June 2016, and will be removed entirely after the July CRAN release. Users with existing code that uses adorn should simply plot the panels individually, and use conventional R functions, e.g. lines etc., after each panel, to achieve the desired effect. (See oce-defunct for notes on other deprecated or defunct oce features.)
fill
boolean, set TRUE to fill the curve to zero (which it does incorrectly if there are missing values in y).
xaxs
control x axis ending; see par("xaxs").
yaxs
control y axis ending; see par("yaxs").
cex
size of labels on axes; see par("cex").
cex.axis
see par("cex.axis").
cex.main
see par("cex.main").
mgp
3-element numerical vector to use for par(mgp), and also for par(mar), computed from this. The default is tighter than the R default, in order to use more space for the data and less for the axes.
mar
value to be used with par("mar") to set margins. THe default value uses significantly tighter margins than is the norm in R, which gives more space for the data. However, in doing this, the existing par("mar") value is ignored, which contradicts values that may have been set by a previous call to drawPalette. To get plot with a palette, first call drawPalette, then call oce.plot.ts with mar=par("mar").
main
title of plot.
despike
boolean flag that can turn on despiking with despike.
axes
boolean, set to TRUE to get axes plotted
tformat
optional format for labels on the time axis
marginsAsImage
boolean indicatingn whether to set the right-hand margin to the width normally taken by an image drawn with imagep.
grid
if TRUE, a grid will be drawn for each panel. (This argument is needed, because calling grid after doing a sequence of plots will not result in useful results for the individual panels.
grid.col
colour of grid
grid.lty
line type of grid
grid.lwd
line width of grid
debug
a flag that turns on debugging. Set to 1 to get a moderate amount of debugging information, or to 2 to get more.
...
graphical parameters passed down to plot.

Value

A list is silently returned, containing xat and yat, values that can be used by oce.grid to add a grid to the plot.

Details

Depending on the version of R, the standard plot and plot.ts routines will not obey the time zone of the data. This routine gets around that problem. It can also plot the time range in the top-left margin, if desired; this string includes the timezone, to remove any possible confusion. The time axis is drawn with oce.axis.POSIXct.

Examples

Run this code

library(oce)
t0 <- as.POSIXct("2008-01-01", tz="UTC")
t <- seq(t0, length.out=48, by="30 min")
y <- sin(as.numeric(t - t0) * 2 * pi / (12 * 3600))
oce.plot.ts(t, y, type='l', xaxs='i')

Run the code above in your browser using DataLab