Time series plot with categories shown as a stacked bar chart
trend_prop.Rd
This function shows time series plots as stacked bar charts. The different
categories in the bar chart are made up from a character or factor variable
in a data frame. The function is primarily developed to support the plotting
of cluster analysis output from polar_cluster()
and
openair::trajCluster()
that consider local and regional (back trajectory)
cluster analysis respectively. However, the function has more general use for
understanding time series data.
Usage
trend_prop(
data,
pollutant,
proportion,
avg_time = "month",
facet = "default",
normalise = FALSE
)
Arguments
- data
A data frame containing the fields
date
,pollutant
and a splitting variableproportion
- pollutant
Name of the pollutant to plot contained in
mydata
.- proportion
The splitting variable that makes up the bars in the bar chart e.g.
proportion = "cluster"
if the output frompolarCluster
is being analysed. Ifproportion
is a numeric variable it is split into 4 quantiles (by default) bycutData
. Ifproportion
is a factor or character variable then the categories are used directly.- avg_time
This defines the time period to average to. Can be “sec”, “min”, “hour”, “day”, “DSTday”, “week”, “month”, “quarter” or “year”. For much increased flexibility a number can precede these options followed by a space. For example, a timeAverage of 2 months would be
period = "2 month"
.Note that
avg_time
when used intimeProp
should be greater than the time gap in the original data. For example,avg_time = "day"
for hourly data is OK, butavg_time = "hour"
for daily data is not.- facet
facet
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 incutData
e.g. "season", "year", "weekday" and so on. For example,facet = "season"
will produce four plots --- one for each season.It is also possible to choose
facet
as another variable in the data frame. If that variable is numeric, then the data will be split into four quantiles (if possible) and labelled accordingly. If facet is an existing character or factor variable, then those categories/levels will be used directly. This offers great flexibility for understanding the variation of different variables and how they depend on one another.facet
must be of length one.- normalise
If
normalise = TRUE
then each time interval is scaled to 100. This is helpful to show the relative (percentage) contribution of the proportions.
Value
A ggplot2::ggplot2 figure
Details
In order to plot time series in this way, some sort of time aggregation is
needed, which is controlled by the option avg_time
.
The plot shows the value of pollutant
on the y-axis (averaged
according to avg_time
). The time intervals are made up of bars split
according to proportion
. The bars therefore show how the total value
of pollutant
is made up for any time interval.
See also
Other time series and trend functions:
trend_calendar()
,
trend_level()
,
trend_variation()
Other cluster analysis functions:
polar_cluster()