timePlot(mydata, pollutant = "nox", group = FALSE, stack = FALSE,
normalise = NULL, avg.time = "default", data.thresh = 0,
statistic = "mean", percentile = NA, date.pad = FALSE,
type = "default", cols = "brewer1", plot.type = "l", key = TRUE,
log = FALSE, smooth = FALSE, ci = TRUE, y.relation = "same",
ref.x = NULL, ref.y = NULL, key.columns = 1, name.pol = pollutant,
date.breaks = 7, date.format = NULL, auto.text = TRUE, ...)
date
field
and at least one variable to plot.pollutant = c("nox", "co")
should be used.FALSE
, which
means they are plotted in separate panels with their own scaled. If
TRUE
then they are plotted on the samTRUE
the time series will be stacked by year. This
option can be useful if there are several years worth of data making it
difficult to see much detail when plotted on a single plot.normalise
can take two values, either
norm
avg.time
. A value of zero means that all available
data will be used in a particular period regardless if of the number of
values available. Conversely, a value of 100 wstatistic =
"percentile"
and when aggregating the data with avg.time
. More
than one percentile level is allowed for type = "default"
e.g.
percentile = c(50, 95)
. Nodate.pad = TRUE
the time gaps between the
chunks are shown properly, rather than with a ltype
determines how the data are split
i.e. conditioned, and then plotted. The default is will produce a
single plot using the entire data. Type can be one of the built-in
types as detailed in cutData
e.g. RColorBrewer
colours --- see the openair
openColours
function lattice
plot type, which is a line
(plot.type = "l"
) by default. Another useful option is
plot.type = "h"
, which draws vertical lines.TRUE
.FALSE
. If TRUE
a well-formatted log10 scale is used. This
can be useful for plotting data for several different pollutants that
exist on very different scales. It is therFALSE
.ci
determines
whether the 95% confidence intervals aer shown.ref.y
for details. In this case the
correct date format should be used for a vertical line e.g. ref.x
= list(v = as.POSIXct("2000-06-15"), lty = 5)
.ref.y =
list(h = 50, lty = 5)
will add a dashed horizontal line at
50. Several lines can be plotted e.g. ref.y = list(h = c(50,
100
columns
to be less than
the number of pollutants.timePlot
generally sets the date format
sensibly there can be some situations where the user wishes to
have more control. For format types see strptime
. For
example, tTRUE
(default) or FALSE
. If
TRUE
titles and axis labels will automatically try and
format pollutant names and units properly e.g. by subscripting
the cutData
and
lattice:xyplot
. For example, timePlot
passes the option
hemisphere = "southern"
on to cutData
to provide southern
(rather than defautimePlot
also returns
an object of class ``openair''. The object includes three main
components: call
, the command used to generate the plot;
data
, the data frame of summarised information used to make the
plot; and plot
, the plot itself. If retained, e.g. using
output <- timePlot(mydata, "nox")
, this output can be used to
recover the data, reproduce or rework the original plot or undertake
further analysis.
An openair output can be manipulated using a number of generic operations,
including print
, plot
and summary
.timePlot
is the basic time series plotting function in
openair
. Its purpose is to make it quick and easy to plot time
series for pollutants and other variables. The other purpose is to plot
potentially many variables together in as compact a way as possible.
The function is flexible enough to plot more than one variable at once. If
more than one variable is chosen plots it can either show all variables on
the same plot (with different line types) on the same scale, or (if
group = FALSE
) each variable in its own panels with its own scale.
The general preference is not to plot two variables on the same graph with
two different y-scales. It can be misleading to do so and difficult with
more than two variables. If there is in interest in plotting several
variables together that have very different scales, then it can be useful
to normalise the data first, which can be down be setting the
normalise
option.
The user has fine control over the choice of colours, line width and line
types used. This is useful for example, to emphasise a particular variable
with a specific line type/colour/width.
timePlot
works very well with selectByDate
, which is
used for selecting particular date ranges quickly and easily. See examples
below.
By default plots are shown with a colour key at the bottom and in teh case
of multiple pollutants or sites, strips on the left of each plot. Sometimes
this may be overkill and the user can opt to remove the key and/or the
strip by setting key
and/or strip
to FALSE
. One reason
to do this is to maximise the plotting area and therefore the information
shown.TheilSen
, smoothTrend
,
linearRelation
, selectByDate
and
timeAverage
for details on selecting averaging times and
other statistics in a flexible way# basic use, single pollutant
timePlot(mydata, pollutant = "nox")
# two pollutants in separate panels
timePlot(mydata, pollutant = c("nox", "no2"))
# two pollutants in the same panel with the same scale
timePlot(mydata, pollutant = c("nox", "no2"), group = TRUE)
# alternative by normalising concentrations and plotting on the same
scale
timePlot(mydata, pollutant = c("nox", "co", "pm10", "so2"), group = TRUE, avg.time =
"year", normalise = "1/1/1998", lwd = 3, lty = 1)
# examples of selecting by date
# plot for nox in 1999
timePlot(selectByDate(mydata, year = 1999), pollutant = "nox")
# select specific date range for two pollutants
timePlot(selectByDate(mydata, start = "6/8/2003", end = "13/8/2003"),
pollutant = c("no2", "o3"))
# choose different line styles etc
timePlot(mydata, pollutant = c("nox", "no2"), lty = 1)
# choose different line styles etc
timePlot(selectByDate(mydata, year = 2004, month = 6), pollutant =
c("nox", "no2"), lwd = c(1, 2), col = "black")
# different averaging times
#daily mean O3
timePlot(mydata, pollutant = "o3", avg.time = "day")
# daily mean O3 ensuring each day has data capture of at least 75\%
timePlot(mydata, pollutant = "o3", avg.time = "day", data.thresh = 75)
# 2-week average of O3 concentrations
timePlot(mydata, pollutant = "o3", avg.time = "2 week")
Run the code above in your browser using DataLab