| timePlot | R Documentation |
The 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.
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",
log = FALSE,
windflow = NULL,
smooth = FALSE,
smooth_k = NULL,
ci = TRUE,
x.relation = "same",
y.relation = "same",
ref.x = NULL,
ref.y = NULL,
key.columns = NULL,
key.position = "bottom",
strip.position = "top",
name.pol = pollutant,
date.breaks = 7,
date.format = NULL,
auto.text = TRUE,
plot = TRUE,
key = NULL,
...
)
mydata |
A data frame of time series. Must include a |
pollutant |
Name of variable to plot. Two or more pollutants can be
plotted, in which case a form like |
group |
Controls how multiple lines/series are grouped. Three options are available:
|
stack |
If |
normalise |
Should variables be normalised? The default is is not to
normalise the data. |
avg.time |
This defines the time period to average to. Can be Note that |
data.thresh |
The data capture threshold to use (%). 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
will mean that all data will need to be present for the average to be
calculated, else it is recorded as |
statistic |
The statistic to apply when aggregating the data; default is
the mean. Can be one of |
percentile |
The percentile level in percent used when |
date.pad |
Should missing data be padded-out? This is useful where a
data frame consists of two or more "chunks" of data with time gaps between
them. By setting |
type |
Character string(s) defining how data should be split/conditioned
before plotting.
Most |
cols |
Colours to use for plotting. Can be a pre-set palette (e.g.,
|
log |
Should the y-axis appear on a log scale? The default is |
windflow |
If |
smooth |
Should a smooth line be applied to the data? The default is
|
smooth_k |
An integer controlling the number of basis functions used in
the GAM smooth. In a GAM, |
ci |
If a smooth fit line is applied, then |
x.relation, y.relation |
This determines how the x- and y-axis scales are
plotted. |
ref.x |
See |
ref.y |
A list with details of the horizontal lines to be added
representing reference line(s). For example, |
key.columns |
Number of columns to be used in a categorical legend. With
many categories a single column can make to key too wide. The user can thus
choose to use several columns by setting |
key.position |
Location where the legend is to be placed. Allowed
arguments include |
strip.position |
Location where the facet 'strips' are located when
using |
name.pol |
This option can be used to give alternative names for the
variables plotted. Instead of taking the column headings as names, the user
can supply replacements. For example, if a column had the name "nox" and
the user wanted a different description, then setting |
date.breaks |
Number of major x-axis intervals to use. The function will
try and choose a sensible number of dates/times as well as formatting the
date/time appropriately to the range being considered. The user can
override this behaviour by adjusting the value of |
date.format |
This option controls the date format on the x-axis. A
sensible format is chosen by default, but the user can set |
auto.text |
Either |
plot |
When |
key |
Deprecated; please use |
... |
Addition options are passed on to
|
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.
an openair object
David Carslaw
Jack Davison
Other time series and trend functions:
TheilSen(),
calendarPlot(),
smoothTrend(),
timeProp(),
timeVariation()
# basic use, single pollutant
timePlot(mydata, pollutant = "nox")
# two pollutants in separate panels
## Not run:
timePlot(mydata, pollutant = c("nox", "no2"))
# two pollutants in the same panel with the same scale
timePlot(mydata, pollutant = c("nox", "no2"), group = TRUE)
# group by a column (e.g. long-format data with a 'site' column)
d <- rbind(
cbind(mydata[, c("date", "nox")], site = "London"),
cbind(transform(mydata[, c("date", "nox")], nox = nox * 1.5), site = "Manchester")
)
timePlot(d, pollutant = "nox", group = "site")
# 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")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.