polarFreq primarily plots wind speed-direction frequencies in
‘bins’. Each bin is colour-coded depending on the frequency of
measurements. Bins can also be used to show the concentration of pollutants
using a range of commonly used statistics.
polarFreq(
mydata,
pollutant = NULL,
statistic = "frequency",
ws.int = 1,
wd.nint = 36,
grid.line = 5,
breaks = NULL,
labels = NULL,
cols = "default",
trans = TRUE,
type = "default",
min.bin = 1,
ws.upper = NA,
offset = 10,
border.col = "transparent",
key.title = paste(statistic, pollutant, sep = " "),
key.position = "right",
strip.position = "top",
auto.text = TRUE,
plot = TRUE,
key = NULL,
...
)an openair object
A data frame minimally containing ws, wd and date.
Mandatory. A pollutant name corresponding to a variable in a
data frame should be supplied e.g. pollutant = "nox"
The statistic that should be applied to each wind speed/direction bin. Can be one of:
"frequency": the simplest and plots the frequency of wind speed/direction in
different bins. The scale therefore shows the counts in each bin.
"mean", "median", "max" (maximum), "stdev" (standard deviation):
Plots the relevant summary statistic of a pollutant in wind speed/direction
bins.
"weighted.mean" will plot the concentration of a pollutant
weighted by wind speed/direction. Each segment therefore provides the
percentage overall contribution to the total concentration.
Note that for options other than "frequency", it is necessary to also
provide the name of a pollutant.
Wind speed interval assumed. In some cases e.g. a low met mast, an interval of 0.5 may be more appropriate.
Number of intervals of wind direction.
Radial spacing of grid lines.
If a categorical colour scale is required then breaks
should be specified. These should be provided as a numeric vector, e.g.,
breaks = c(0, 50, 100, 1000). Users should set the maximum value of
breaks to exceed the maximum data value to ensure it is within the
maximum final range, e.g., 100--1000 in this case. Labels will
automatically be generated, but can be customised by passing a character
vector to labels, e.g., labels = c("good", "bad", "very bad"). In this
example, 0 - 50 will be "good" and so on. Note there is one less label
than break.
Colours to use for plotting. Can be a pre-set palette (e.g.,
"turbo", "viridis", "tol", "Dark2", etc.) or a user-defined vector
of R colours (e.g., c("yellow", "green", "blue", "black") - see
colours() for a full list) or hex-codes (e.g., c("#30123B", "#9CF649", "#7A0403")). See openColours() for more details.
Should a transformation be applied? Sometimes when producing
plots of this kind they can be dominated by a few high points. The default
therefore is TRUE and a square-root transform is applied. This results in
a non-linear scale and (usually) a better representation of the
distribution. If set to FALSE a linear scale is used.
Character string(s) defining how data should be split/conditioned
before plotting. "default" produces a single panel using the entire
dataset. Any other options will split the plot into different panels - a
roughly square grid of panels if one type is given, or a 2D matrix of
panels if two types are given. type is always passed to cutData(),
and can therefore be any of:
A built-in type defined in cutData() (e.g., "season", "year",
"weekday", etc.). For example, type = "season" will split the plot into
four panels, one for each season.
The name of a numeric column in mydata, which will be split into
n.levels quantiles (defaulting to 4).
The name of a character or factor column in mydata, which will be used
as-is. Commonly this could be a variable like "site" to ensure data from
different monitoring sites are handled and presented separately. It could
equally be any arbitrary column created by the user (e.g., whether a nearby
possible pollutant source is active or not).
Most openair plotting functions can take two type arguments. If two are
given, the first is used for the columns and the second for the rows.
The minimum number of points allowed in a wind speed/wind
direction bin. The default is 1. A value of two requires at least 2 valid
records in each bin an so on; bins with less than 2 valid records are set
to NA. Care should be taken when using a value > 1 because of the risk of
removing real data points. It is recommended to consider your data with
care. Also, the polarFreq function can be of use in such circumstances.
A user-defined upper wind speed to use. This is useful for
ensuring a consistent scale between different plots. For example, to always
ensure that wind speeds are displayed between 1-10, set ws.int = 10.
offset controls the size of the 'hole' in the middle and is
expressed on a scale of 0 to 100, where 0 is no hole and 100 is a
hole that takes up the entire plotting area.
The colour of the boundary of each wind speed/direction bin. The default is transparent. Another useful choice sometimes is "white".
Used to set the title of the legend. The legend title is
passed to quickText() if auto.text = TRUE.
Location where the legend is to be placed. Allowed
arguments include "top", "right", "bottom", "left" and "none",
the last of which removes the legend entirely.
Location where the facet 'strips' are located when
using type. When one type is provided, can be one of "left",
"right", "bottom" or "top". When two types are provided, this
argument defines whether the strips are "switched" and can take either
"x", "y", or "both". For example, "x" will switch the 'top' strip
locations to the bottom of the plot.
Either TRUE (default) or FALSE. If TRUE titles and
axis labels will automatically try and format pollutant names and units
properly, e.g., by subscripting the "2" in "NO2". Passed to quickText().
When openair plots are created they are automatically printed
to the active graphics device. plot = FALSE deactivates this behaviour.
This may be useful when the plot data is of more interest, or the plot is
required to appear later (e.g., later in a Quarto document, or to be saved
to a file).
Deprecated; please use key.position. If FALSE, sets
key.position to "none".
Addition options are passed on to cutData() for type handling.
Some additional arguments are also available:
xlab, ylab and main override the x-axis label, y-axis label, and plot title.
layout sets the layout of facets - e.g., layout(2, 5) will have 2 columns and 5 rows.
fontsize overrides the overall font size of the plot.
annotate = FALSE will not plot the N/E/S/W labels.
limits sets the colour bar limits, if breaks is not used.
David Carslaw
polarFreq is its default use provides details of wind speed and direction
frequencies. In this respect it is similar to windRose(), but considers
wind direction intervals of 10 degrees and a user-specified wind speed
interval. The frequency of wind speeds/directions formed by these
‘bins’ is represented on a colour scale.
The polarFreq function is more flexible than either windRose() or
polarPlot(). It can, for example, also consider pollutant concentrations
(see examples below). Instead of the number of data points in each bin, the
concentration can be shown. Further, a range of statistics can be used to
describe each bin - see statistic above. Plotting mean concentrations is
useful for source identification and is the same as polarPlot() but without
smoothing, which may be preferable for some data. Plotting with statistic = "weighted.mean" is particularly useful for understanding the relative
importance of different source contributions. For example, high mean
concentrations may be observed for high wind speed conditions, but the
weighted mean concentration may well show that the contribution to overall
concentrations is very low.
polarFreq also offers great flexibility with the scale used and the user
has fine control over both the range, interval and colour.
Other polar directional analysis functions:
percentileRose(),
polarAnnulus(),
polarCluster(),
polarDiff(),
polarPlot(),
pollutionRose(),
windRose()
# basic wind frequency plot
polarFreq(mydata)
# wind frequencies by year
if (FALSE) {
polarFreq(mydata, type = "year")
}
# mean SO2 by year, showing only bins with at least 2 points
if (FALSE) {
polarFreq(mydata, pollutant = "so2", type = "year", statistic = "mean", min.bin = 2)
}
# weighted mean SO2 by year, showing only bins with at least 2 points
if (FALSE) {
polarFreq(mydata,
pollutant = "so2", type = "year", statistic = "weighted.mean",
min.bin = 2
)
}
# windRose for just 2000 and 2003 with different colours
if (FALSE) {
polarFreq(subset(mydata, format(date, "%Y") %in% c(2000, 2003)),
type = "year", cols = "turbo"
)
}
# user defined breaks from 0-700 in intervals of 100 (note linear scale)
if (FALSE) {
polarFreq(mydata, breaks = seq(0, 700, 100))
}
# more complicated user-defined breaks - useful for highlighting bins
# with a certain number of data points
if (FALSE) {
polarFreq(mydata, breaks = c(0, 10, 50, 100, 250, 500, 700))
}
# source contribution plot and use of offset option
if (FALSE) {
polarFreq(mydata,
pollutant = "pm25",
statistic = "weighted.mean", offset = 50, ws.int = 25, trans = FALSE
)
}
Run the code above in your browser using DataLab