View source: R/timeVariation.R
| timeVariation | R Documentation |
Plots temporal variation for different variables, typically pollutant
concentrations, across user-defined time scales. Multiple panels can be
shown, such as hour of the day, day of the week, week of the year, month of
the year, annual mean, or any other time-based grouping the user specifies.
By default, this function plots the diurnal, day of the week and monthly
variation for different variables, typically pollutant concentrations. Four
separate plots are produced. This is a convenient alternative to using
variationPlot() and assembling the plots manually.
timeVariation(
mydata,
pollutant = "nox",
panels = c("hour.weekday", "hour", "month", "weekday"),
local.tz = NULL,
normalise = FALSE,
xlab = NULL,
name.pol = NULL,
type = "default",
group = NULL,
difference = FALSE,
statistic = "mean",
conf.int = NULL,
B = 100,
ci = TRUE,
cols = "hue",
ref.y = NULL,
key = NULL,
key.columns = NULL,
key.position = "top",
strip.position = "top",
panel.gap = 1.5,
auto.text = TRUE,
alpha = 0.4,
plot = TRUE,
...
)
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 |
panels |
A vector of character values which can be passed to
|
local.tz |
Used for identifying whether a date has daylight savings time
(DST) applied or not. Examples include |
normalise |
Should variables be normalised? The default is |
xlab |
x-axis label; one for each |
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 |
type |
It is also possible to choose Only one |
group |
This sets the grouping variable to be used. For example, if a
data frame had a column |
difference |
If two pollutants are chosen then setting |
statistic |
Can be |
conf.int |
The confidence intervals to be plotted. If |
B |
Number of bootstrap replicates to use. Can be useful to reduce this value when there are a large number of observations available to increase the speed of the calculations without affecting the 95% confidence interval calculations by much. |
ci |
Should confidence intervals be shown? The default is |
cols |
Colours to use for plotting. Can be a pre-set palette (e.g.,
|
ref.y |
A list with details of the horizontal lines to be added
representing reference line(s). For example, |
key |
By default |
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 |
panel.gap |
The gap between panels in any split panel (e.g., the default
|
auto.text |
Either |
alpha |
The alpha transparency used for plotting confidence intervals.
|
plot |
When |
... |
Addition options are passed on to
|
The variation of pollutant concentrations by time can reveal many interesting features that relate to source types and meteorology. For traffic sources, there are often important differences in the way vehicles vary by type - e.g., fewer heavy vehicles at weekends.
Users can supply their own ylim, e.g. ylim = c(0, 200), which will be
used for all plots. Alternatively, ylim can be a list equal to the length
of panels to control y-limits for each individual panel, e.g. ylim = list(c(-100,500), c(200, 300), c(-400,400), c(50,70)).
Note also that the timeVariation() function works well on a subset of data
and in conjunction with other plots. For example, a polarPlot() may
highlight an interesting feature for a particular wind speed/direction range.
By filtering for those conditions timeVariation() can help determine
whether the temporal variation of that feature differs from other features
— and help with source identification.
an openair object. The components of
timeVariation() are named after panels. main.plot is a
patchwork assembly.
David Carslaw
Jack Davison
Other time series and trend functions:
TheilSen(),
calendarPlot(),
smoothTrend(),
timePlot(),
timeProp()
# basic use
timeVariation(mydata, pollutant = "nox")
# for a subset of conditions
## Not run:
timeVariation(subset(mydata, ws > 3 & wd > 100 & wd < 270),
pollutant = "pm10", ylab = "pm10 (ug/m3)"
)
# multiple pollutants with concentrations normalised
timeVariation(mydata, pollutant = c("nox", "co"), normalise = TRUE)
# show BST/GMT variation (see ?cutData for more details)
# the NOx plot shows the profiles are very similar when expressed in
# local time, showing that the profile is dominated by a local source
# that varies by local time and not by GMT i.e. road vehicle emissions
timeVariation(mydata, pollutant = "nox", type = "dst", local.tz = "Europe/London")
# In this case it is better to group the results for clarity:
timeVariation(mydata, pollutant = "nox", group = "dst", local.tz = "Europe/London")
# By contrast, a variable such as wind speed shows a clear shift when
# expressed in local time. These two plots can help show whether the
# variation is dominated by man-made influences or natural processes
timeVariation(mydata, pollutant = "ws", group = "dst", local.tz = "Europe/London")
# It is also possible to plot several variables and set type. For
# example, consider the NOx and NO2 split by levels of O3:
timeVariation(mydata, pollutant = c("nox", "no2"), type = "o3", normalise = TRUE)
# difference in concentrations
timeVariation(mydata, poll = c("pm25", "pm10"), difference = TRUE)
# It is also useful to consider how concentrations vary by
# considering two different periods e.g. in intervention
# analysis. In the following plot NO2 has clearly increased but much
# less so at weekends - perhaps suggesting vehicles other than cars
# are important because flows of cars are approximately invariant by
# day of the week
mydata <- splitByDate(mydata, dates = "1/1/2003", labels = c("before Jan. 2003", "After Jan. 2003"))
timeVariation(mydata, pollutant = "no2", group = "split.by", difference = TRUE)
# sub plots can be extracted from the openair object
myplot <- timeVariation(mydata, pollutant = "no2")
myplot$plot$hour.weekday
# individual plots
myplot$plot$hour.weekday
myplot$plot$hour
myplot$plot$day
myplot$plot$month
# numerical results (mean, lower/upper uncertainties)
myplot$data$hour.weekday
myplot$data$hour
myplot$data$day
myplot$data$month
# plot quantiles and median
timeVariation(
mydata,
statistic = "median",
poll = "pm10",
cols = "firebrick"
)
# with different intervals
timeVariation(
mydata,
statistic = "median",
poll = "pm10",
conf.int = c(0.75, 0.99),
cols = "firebrick"
)
# with different (arbitrary) panels
# note 'hemisphere' is passed to cutData() for season
timeVariation(
mydata,
pollutant = "no2",
panels = c("weekday.season", "year", "wd"),
hemisphere = "southern"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.