diff --git a/.Rbuildignore b/.Rbuildignore index 4e3231b9..0322baa3 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,4 @@ README_cache ^\.github$ ^pkgdown$ ^LICENSE\.md$ +^vignettes/articles$ diff --git a/.gitignore b/.gitignore index eb3e7638..45844375 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ README_cache/* .DS_Store docs *.html +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index cc00f4e5..dd2f1c3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,9 +48,11 @@ Imports: utils Suggests: KernSmooth, + knitr, mapdata, maps, quantreg, + rmarkdown, spelling LinkingTo: Rcpp @@ -61,3 +63,4 @@ LazyData: yes LazyLoad: yes Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +VignetteBuilder: knitr diff --git a/README.Rmd b/README.Rmd deleted file mode 100644 index 0fee187b..00000000 --- a/README.Rmd +++ /dev/null @@ -1,197 +0,0 @@ ---- -output: github_document -editor_options: - markdown: - wrap: 72 ---- - - - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - warning = FALSE, - fig.retina = 2, - message = FALSE, - eval = FALSE, - comment = "#>", - fig.path = "man/figures/README-", - out.width = "100%" -) -``` - -# openair: open source tools for air quality data analysis - - - -[![R-CMD-check](https://github.com/davidcarslaw/openair/workflows/R-CMD-check/badge.svg)](https://github.com/davidcarslaw/openair/actions) -[![CRAN -status](https://www.r-pkg.org/badges/version/openair)](https://CRAN.R-project.org/package=openair) -![](http://cranlogs.r-pkg.org/badges/grand-total/openair) - - -**openair** is an R package developed for the purpose of analysing air -quality data --- or more generally atmospheric composition data. The -package is extensively used in academia, the public and private sectors. -The project was initially funded by the UK Natural Environment Research -Council ([NERC](https://www.ukri.org/councils/nerc/)), with additional funds from -Defra. - -The most up to date information on `openair` can be found in the package -itself and at the book website -(). - -## Installation - -Installation can be done in the normal way: - -```{r eval=FALSE} -install.packages("openair") -``` - -The development version can be installed from GitHub. Installation of -`openair` from GitHub is easy using the `pak` package. Note, -because `openair` contains C++ code a compiler is also needed. For -Windows - for example, -[Rtools](https://cran.r-project.org/bin/windows/Rtools/) is needed. - -``` r -# install.packages("pak") -pak::pak("davidcarslaw/openair") -``` - -## Description - -`openair` has developed over several years to help analyse air quality -data. - -This package continues to develop and input from other developers would -be welcome. A summary of some of the features are: - -- **Access to data** from several hundred UK air pollution monitoring - sites through the `importAURN` and family functions. -- **Utility functions** such as `timeAverage` and `selectByDate` to - make it easier to manipulate atmospheric composition data. -- Flexible **wind and pollution roses** through `windRose` and - `pollutionRose`. -- Flexible plot conditioning to easily plot data by hour or the day, - day of the week, season etc. through the `openair` `type` option - available in most functions. -- More sophisticated **bivariate polar plots** and conditional - probability functions to help characterise different sources of - pollution. A paper on the latter is available - [here](https://www.sciencedirect.com/science/article/pii/S1364815214001339). -- Access to NOAA Hysplit pre-calculated annual 96-hour back - **trajectories** and many plotting and analysis functions e.g. - trajectory frequencies, Potential Source Contribution Function and - trajectory clustering. -- Many functions for air quality **model evaluation** using the - flexible methods described above e.g. the `type` option to easily - evaluate models by season, hour of the day etc. These include key - model statistics, Taylor Diagram, Conditional Quantile plots. - -## Brief examples - -### Import data from the UK Automatic Urban and Rural Network - -It is easy to import hourly data from 100s of sites and to import -several sites at one time and several years of data. - -```{r library, eval=TRUE} -library(openair) -kc1 <- importAURN(site = "kc1", year = 2020) -kc1 -``` - -### Utility functions - -Using the `selectByDate` function it is easy to select quite complex -time-based periods. For example, to select weekday (Monday to Friday) -data from June to September for 2012 *and* for the hours 7am to 7pm -inclusive: - -```{r selectbydate, eval = TRUE} -sub <- selectByDate(kc1, - day = "weekday", - year = 2020, - month = 6:9, - hour = 7:19 -) -sub -``` - -Similarly it is easy to time-average data in many flexible ways. For -example, 2-week means can be calculated as - -```{r timeaverage, eval=TRUE} -sub2 <- timeAverage(kc1, avg.time = "2 week") -``` - -### The `type` option - -One of the key aspects of `openair` is the use of the `type` option, -which is available for almost all `openair` functions. The `type` option -partitions data by different categories of variable. There are many -built-in options that `type` can take based on splitting your data by -different date values. A summary of in-built values of type are: - -- "year" splits data by year -- "month" splits variables by month of the year -- "monthyear" splits data by year *and* month -- "season" splits variables by season. Note in this case the user can - also supply a `hemisphere` option that can be either "northern" - (default) or "southern" -- "weekday" splits variables by day of the week -- "weekend" splits variables by Saturday, Sunday, weekday -- "daylight" splits variables by nighttime/daytime. Note the user must - supply a `longitude` and `latitude` -- "dst" splits variables by daylight saving time and non-daylight - saving time (see manual for more details) -- "wd" if wind direction (`wd`) is available `type = "wd"` will split - the data up into 8 sectors: N, NE, E, SE, S, SW, W, NW. -- "seasonyear (or"yearseason") will split the data into year-season - intervals, keeping the months of a season together. For example, - December 2010 is considered as part of winter 2011 (with January and - February 2011). This makes it easier to consider contiguous seasons. - In contrast, `type = "season"` will just split the data into four - seasons regardless of the year. - -If a categorical variable is present in a data frame e.g. `site` then -that variables can be used directly e.g. `type = "site"`. - -`type` can also be a numeric variable. In this case the numeric variable -is split up into 4 *quantiles* i.e. four partitions containing equal -numbers of points. Note the user can supply the option `n.levels` to -indicate how many quantiles to use. - -### Example directional analysis - -`openair` can plot basic wind roses very easily provided the variables -`ws` (wind speed) and `wd` (wind direction) are available. - -```{r windrose, eval = TRUE, fig.width = 4, fig.cap="A wind rose summarising the wind conditions at a monitoring station.", fig.height = 4.5, out.width = '50%', fig.alt="A polar bar chart showing the proportion of wind coming from 12 compass directions, where we show most wind at the monitoring station arrives from the South West."} -windRose(mydata) -``` - -However, the real flexibility comes from being able to use the `type` -option. - -```{r windrose2, eval = TRUE, fig.width = 10, fig.height = 5, out.width = '100%', fig.cap="Wind roses summarising the wind conditions at a monitoring station per year, demonstrating the `{openair}` type option.", fig.alt="Polar bar charts showing the proportion of wind coming from 12 compass directions. There are 8 charts, each representing a year of data from 1998 to 2005. While there is a small amount of variation, the dominant wind direction for each year is from the south west."} -windRose(mydata, - type = "year", - layout = c(4, 2) -) -``` - -There are many flavours of bivariate polar plots, as described -[here](https://bookdown.org/david_carslaw/openair/sections/directional-analysis/polar-plots.html) that -are useful for understanding air pollution sources. - -```{r polarCPF, eval = TRUE, fig.width = 4.5, fig.height = 4, out.width = '60%', fig.cap="A bivariate polar plot showing the wind conditions which give rise to elevated pollutant concentrations.", fig.alt="A polar heatmap with wind direction on the spoke axes and wind speed on the radial axes showing the probability of sulfur dioxide being higher than the 90th percentile. The chart indicates the highest probabilities occur when the wind is coming from the east and is blowing at between 0 and 12 metres per second."} -polarPlot(mydata, - pollutant = "so2", - statistic = "cpf", - percentile = 90, - cols = "YlGnBu" -) -``` diff --git a/README.md b/README.md index d14d1416..39c3b892 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ - +
-# openair: open source tools for air quality data analysis + + +## **openair** +### open source tools for air quality data analysis @@ -9,231 +12,88 @@ [![CRAN status](https://www.r-pkg.org/badges/version/openair)](https://CRAN.R-project.org/package=openair) ![](http://cranlogs.r-pkg.org/badges/grand-total/openair) + +[![github](https://img.shields.io/badge/CODE-github-black?logo=github)](https://github.com/davidcarslaw/openair) +[![website](https://img.shields.io/badge/DOCS-website-black)](https://davidcarslaw.github.io/openair) +[![book](https://img.shields.io/badge/DOCS-book-black)](https://bookdown.org/david_carslaw/openair/) -**openair** is an R package developed for the purpose of analysing air -quality data — or more generally atmospheric composition data. The -package is extensively used in academia, the public and private sectors. -The project was initially funded by the UK Natural Environment Research -Council ([NERC](https://www.ukri.org/councils/nerc/)), with additional -funds from Defra. +
-The most up to date information on `openair` can be found in the package -itself and at the book website -(). +**openair** is an R package developed for the purpose of analysing air quality data — or more generally atmospheric composition data. The package is extensively used in academia, the public and private sectors. The project was initially funded by the UK Natural Environment Research Council ([NERC](https://www.ukri.org/councils/nerc/)), with additional funds from the UK Department for Environment Food & Rural Affairs ([Defra](https://www.gov.uk/government/organisations/department-for-environment-food-rural-affairs)). -## Installation +
-Installation can be done in the normal way: +*Part of the openair toolkit* -``` r -install.packages("openair") -``` +[![openair](https://img.shields.io/badge/openair_core-06D6A0?style=flat-square)](https://davidcarslaw.github.io/openair) | +[![worldmet](https://img.shields.io/badge/worldmet-26547C?style=flat-square)](https://davidcarslaw.github.io/worldmet) | +[![openairmaps](https://img.shields.io/badge/openairmaps-FFD166?style=flat-square)](https://davidcarslaw.github.io/openairmaps) | +[![deweather](https://img.shields.io/badge/deweather-EF476F?style=flat-square)](https://davidcarslaw.github.io/deweather) -The development version can be installed from GitHub. Installation of -`openair` from GitHub is easy using the `pak` package. Note, because -`openair` contains C++ code a compiler is also needed. For Windows - for -example, [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is -needed. +
-``` r -# install.packages("pak") -pak::pak("davidcarslaw/openair") -``` +
-## Description - -`openair` has developed over several years to help analyse air quality -data. - -This package continues to develop and input from other developers would -be welcome. A summary of some of the features are: - -- **Access to data** from several hundred UK air pollution monitoring - sites through the `importAURN` and family functions. -- **Utility functions** such as `timeAverage` and `selectByDate` to make - it easier to manipulate atmospheric composition data. -- Flexible **wind and pollution roses** through `windRose` and - `pollutionRose`. -- Flexible plot conditioning to easily plot data by hour or the day, day - of the week, season etc. through the `openair` `type` option available - in most functions. -- More sophisticated **bivariate polar plots** and conditional - probability functions to help characterise different sources of - pollution. A paper on the latter is available - [here](https://www.sciencedirect.com/science/article/pii/S1364815214001339). -- Access to NOAA Hysplit pre-calculated annual 96-hour back - **trajectories** and many plotting and analysis functions e.g. - trajectory frequencies, Potential Source Contribution Function and - trajectory clustering. -- Many functions for air quality **model evaluation** using the flexible - methods described above e.g. the `type` option to easily evaluate - models by season, hour of the day etc. These include key model - statistics, Taylor Diagram, Conditional Quantile plots. - -## Brief examples - -### Import data from the UK Automatic Urban and Rural Network - -It is easy to import hourly data from 100s of sites and to import -several sites at one time and several years of data. +## 💡 Core Features -``` r -library(openair) -kc1 <- importAURN(site = "kc1", year = 2020) -kc1 -#> # A tibble: 8,784 × 15 -#> source site code date co nox no2 no o3 so2 -#> -#> 1 aurn London … KC1 2020-01-01 00:00:00 0.214 64.8 46.2 12.1 1.13 NA -#> 2 aurn London … KC1 2020-01-01 01:00:00 0.237 74.1 45.0 19.0 1.20 NA -#> 3 aurn London … KC1 2020-01-01 02:00:00 0.204 60.5 41.4 12.4 1.50 NA -#> 4 aurn London … KC1 2020-01-01 03:00:00 0.204 53.5 39.8 8.93 1.60 NA -#> 5 aurn London … KC1 2020-01-01 04:00:00 0.169 37.7 33.6 2.63 5.79 NA -#> 6 aurn London … KC1 2020-01-01 05:00:00 0.160 43.3 36.8 4.25 6.09 NA -#> 7 aurn London … KC1 2020-01-01 06:00:00 0.157 48.2 39.4 5.76 2.74 NA -#> 8 aurn London … KC1 2020-01-01 07:00:00 0.178 60.5 44.7 10.3 1.20 NA -#> 9 aurn London … KC1 2020-01-01 08:00:00 0.233 71.8 47.9 15.6 2.25 NA -#> 10 aurn London … KC1 2020-01-01 09:00:00 0.329 128. 46.9 53.2 2.25 NA -#> # ℹ 8,774 more rows -#> # ℹ 5 more variables: pm10 , pm2.5 , ws , wd , -#> # air_temp -``` +**openair** has developed over many years to form an extensive toolkit of functions for analysing air quality and atmospheric composition data. -### Utility functions +- **Access to data** from several hundred UK air pollution monitoring sites through the `importUKAQ()` family of functions. -Using the `selectByDate` function it is easy to select quite complex -time-based periods. For example, to select weekday (Monday to Friday) -data from June to September for 2012 *and* for the hours 7am to 7pm -inclusive: +- **Time Series & Trend analysis** to explore how air quality concentrations vary over time (e.g., through `timePlot()`, `timeVariation()`, and `calendarPlot()`). -``` r -sub <- selectByDate(kc1, - day = "weekday", - year = 2020, - month = 6:9, - hour = 7:19 -) -sub -#> # A tibble: 1,144 × 15 -#> date source site code co nox no2 no o3 so2 -#> -#> 1 2020-06-01 07:00:00 aurn London… KC1 0.125 23.1 16.8 4.14 56.5 2.29 -#> 2 2020-06-01 08:00:00 aurn London… KC1 0.133 25.2 17.8 4.79 61.7 2.68 -#> 3 2020-06-01 09:00:00 aurn London… KC1 0.119 15.6 12.2 2.22 75.8 2.35 -#> 4 2020-06-01 10:00:00 aurn London… KC1 0.104 13.8 11.1 1.79 87.1 1.57 -#> 5 2020-06-01 11:00:00 aurn London… KC1 0.0956 14.0 11.8 1.46 96.7 1.44 -#> 6 2020-06-01 12:00:00 aurn London… KC1 0.0985 11.3 9.97 0.893 106. 1.44 -#> 7 2020-06-01 13:00:00 aurn London… KC1 0.0927 11.0 9.64 0.893 112. 2.03 -#> 8 2020-06-01 14:00:00 aurn London… KC1 0.0927 12.5 10.8 1.14 114. 2.81 -#> 9 2020-06-01 15:00:00 aurn London… KC1 0.0811 10.7 9.48 0.822 115. 2.88 -#> 10 2020-06-01 16:00:00 aurn London… KC1 0.0898 13.9 11.9 1.29 104. 2.22 -#> # ℹ 1,134 more rows -#> # ℹ 5 more variables: pm10 , pm2.5 , ws , wd , -#> # air_temp -``` +- **Directional analysis** to help characterise different sources of pollution, including the creation of **bivariate polar plots** using `polarPlot()`. -Similarly it is easy to time-average data in many flexible ways. For -example, 2-week means can be calculated as +- **Trajectory analysis** to examine NOAA Hysplit trajectories, with plotting (`trajPlot()`), heatmap (`trajLevel()`) and clustering (`trajCluster()`) functionality. -``` r -sub2 <- timeAverage(kc1, avg.time = "2 week") -``` +- **Utility functions**, such as `timeAverage()` and `selectByDate()` to make it easier to manipulate atmospheric composition data. -### The `type` option - -One of the key aspects of `openair` is the use of the `type` option, -which is available for almost all `openair` functions. The `type` option -partitions data by different categories of variable. There are many -built-in options that `type` can take based on splitting your data by -different date values. A summary of in-built values of type are: - -- “year” splits data by year -- “month” splits variables by month of the year -- “monthyear” splits data by year *and* month -- “season” splits variables by season. Note in this case the user can - also supply a `hemisphere` option that can be either “northern” - (default) or “southern” -- “weekday” splits variables by day of the week -- “weekend” splits variables by Saturday, Sunday, weekday -- “daylight” splits variables by nighttime/daytime. Note the user must - supply a `longitude` and `latitude` -- “dst” splits variables by daylight saving time and non-daylight saving - time (see manual for more details) -- “wd” if wind direction (`wd`) is available `type = "wd"` will split - the data up into 8 sectors: N, NE, E, SE, S, SW, W, NW. -- “seasonyear (or”yearseason”) will split the data into year-season - intervals, keeping the months of a season together. For example, - December 2010 is considered as part of winter 2011 (with January and - February 2011). This makes it easier to consider contiguous seasons. - In contrast, `type = "season"` will just split the data into four - seasons regardless of the year. - -If a categorical variable is present in a data frame e.g. `site` then -that variables can be used directly e.g. `type = "site"`. - -`type` can also be a numeric variable. In this case the numeric variable -is split up into 4 *quantiles* i.e. four partitions containing equal -numbers of points. Note the user can supply the option `n.levels` to -indicate how many quantiles to use. - -### Example directional analysis - -`openair` can plot basic wind roses very easily provided the variables -`ws` (wind speed) and `wd` (wind direction) are available. +- **Flexible plot conditioning** to easily plot data by hour or the day, day of the week, season of the year, etc., through the `type` option available in most functions. -``` r -windRose(mydata) +
+ +
+ +
+ +## 📖 Documentation + +All **openair** functions are fully documented; access documentation using R in your IDE of choice. + +```r +?openair::polarPlot ``` -
+Documentation is also hosted online on the **package website**. -A polar bar chart showing the proportion of wind coming from 12 compass directions, where we show most wind at the monitoring station arrives from the South West. -

-A wind rose summarising the wind conditions at a monitoring station. -

+[![website](https://img.shields.io/badge/website-documentation-blue)](https://davidcarslaw.github.io/openair) -
+A guide to the openair toolkit can be found in the **online book**, which contains lots of code snippets, demonstrations of functionality, and ideas for the application of **openair**'s various functions. -However, the real flexibility comes from being able to use the `type` -option. +[![book](https://img.shields.io/badge/book-code_demos_and_ideas-blue)](https://bookdown.org/david_carslaw/openair/) -``` r -windRose(mydata, - type = "year", - layout = c(4, 2) -) -``` +
-
+## 🗃️ Installation -Polar bar charts showing the proportion of wind coming from 12 compass directions. There are 8 charts, each representing a year of data from 1998 to 2005. While there is a small amount of variation, the dominant wind direction for each year is from the south west. -

-Wind roses summarising the wind conditions at a monitoring station per -year, demonstrating the `{openair}` type option. -

+**openair** can be installed from **CRAN** with: -
+``` r +install.packages("openair") +``` -There are many flavours of bivariate polar plots, as described -[here](https://bookdown.org/david_carslaw/openair/sections/directional-analysis/polar-plots.html) -that are useful for understanding air pollution sources. +You can also install the development version of **openair** from GitHub using `{pak}`: ``` r -polarPlot(mydata, - pollutant = "so2", - statistic = "cpf", - percentile = 90, - cols = "YlGnBu" -) +# install.packages("pak") +pak::pak("davidcarslaw/openair") ``` -
+
-A polar heatmap with wind direction on the spoke axes and wind speed on the radial axes showing the probability of sulfur dioxide being higher than the 90th percentile. The chart indicates the highest probabilities occur when the wind is coming from the east and is blowing at between 0 and 12 metres per second. -

-A bivariate polar plot showing the wind conditions which give rise to -elevated pollutant concentrations. -

+🏛️ **openair** is primarily maintained by [David Carslaw](https://github.com/davidcarslaw). -
+📃 **openair** is licensed under the [GNU General Public License](https://davidcarslaw.github.io/openair/LICENSE.html). + +🧑‍💻 Contributions are welcome from the wider community. See the [contributing guide](https://davidcarslaw.github.io/openair/CONTRIBUTING.html) and [code of conduct](https://davidcarslaw.github.io/openair/CODE_OF_CONDUCT.html) for more information. \ No newline at end of file diff --git a/_pkgdown.yml b/_pkgdown.yml index b442dcb5..d7ba2464 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,21 +1,26 @@ url: https://davidcarslaw.github.io/openair/ template: bootstrap: 5 - bootswatch: lumen - pkgdown-nav-height: 100px + bslib: + bootswatch: lumen + pkgdown-nav-height: 100px + navbar: title: openair - type: default - left: - - text: Functions - href: reference/index.html - - text: News - href: news/index.html - - text: Book - href: https://bookdown.org/david_carslaw/openair/ - right: - - icon: fa-github fa-lg - href: https://github.com/davidcarslaw/openair + structure: + left: [intro, reference, news, book, articles, tutorials] + right: [search, github] + components: + reference: + text: Functions + href: reference/index.html + news: + text: News + href: news/index.html + book: + text: Book (external) + href: https://bookdown.org/david_carslaw/openair/ + reference: - title: Data desc: In-built data to demonstrate openair functions. diff --git a/man/figures/README-polarCPF-1.png b/man/figures/README-polarCPF-1.png deleted file mode 100644 index d7056103..00000000 Binary files a/man/figures/README-polarCPF-1.png and /dev/null differ diff --git a/man/figures/README-windrose-1.png b/man/figures/README-windrose-1.png deleted file mode 100644 index b5eae926..00000000 Binary files a/man/figures/README-windrose-1.png and /dev/null differ diff --git a/man/figures/README-windrose2-1.png b/man/figures/README-windrose2-1.png deleted file mode 100644 index b9f8b015..00000000 Binary files a/man/figures/README-windrose2-1.png and /dev/null differ diff --git a/man/figures/feature-banner.png b/man/figures/feature-banner.png new file mode 100644 index 00000000..674de5d2 Binary files /dev/null and b/man/figures/feature-banner.png differ diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 00000000..097b2416 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/articles/openair.Rmd b/vignettes/articles/openair.Rmd new file mode 100644 index 00000000..47296fc8 --- /dev/null +++ b/vignettes/articles/openair.Rmd @@ -0,0 +1,108 @@ +--- +title: "Examples of {openair} Functionality" +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +This vignette outlines some core functionality in `{openair}`. For further examples, please see the [online book](https://bookdown.org/david_carslaw/openair/). + +```{r setup} +library(openair) +``` + +# Import data from the UK Automatic Urban and Rural Network + +It is easy to import hourly data from 100s of sites and to import several sites at one time and several years of data. + +```{r import} +kc1 <- importAURN(site = "kc1", year = 2020) +kc1 +``` + +# Utility functions + +Using the `selectByDate()` function it is easy to select quite complex time-based periods. For example, to select weekday (Monday to Friday) data from June to September for 2012 and for the hours 7am to 7pm inclusive: + +```{r utility} +sub <- selectByDate( + kc1, + day = "weekday", + year = 2020, + month = 6:9, + hour = 7:19 +) +sub +``` + +Similarly it is easy to time-average data in many flexible ways. For example, 2-week means can be calculated as + +```{r timeavg} +sub2 <- timeAverage(kc1, avg.time = "2 week") +sub2 +``` + +# The `type` option + +One of the key aspects of openair is the use of the `type` option, which is available for almost all `{openair}` functions. The `type` option partitions data by different categories of variable. There are many built-in options that `type` can take based on splitting your data by different date values. A summary of in-built values of type are: + +- `"year"` splits data by year + +- `"month"` splits variables by month of the year + +- `"monthyear"` splits data by year and month + +- `"season"` splits variables by season. Note in this case the user can also supply a `hemisphere` option that can be either `"northern"` (default) or `"southern"` + +- `"weekday"` splits variables by day of the week + +- `"weekend"` splits variables by Saturday, Sunday, weekday + +- `"daylight"` splits variables by nighttime/daytime. Note the user must supply a longitude and latitude + +- `"dst"` splits variables by daylight saving time and non-daylight saving time + +- `"wd"` if wind direction (`wd`) is available. `type = "wd"` will split the data up into 8 sectors: N, NE, E, SE, S, SW, W, NW. + +- `"seasonyear"` (or `"yearseason"`) will split the data into year-season intervals, keeping the months of a season together. For example, December 2010 is considered as part of winter 2011 (with January and February 2011). This makes it easier to consider contiguous seasons. In contrast, `type = "season"` will just split the data into four seasons regardless of the year. + +`type` can also use variables already in the data frame: + +- If a categorical variable is specified, e.g., `site` then that variables can be used directly e.g. `type = "site"`. + +- If a numeric numeric variable is specified it is split up into 4 quantiles, i.e., four partitions containing equal numbers of points. Note the user can supply the option `n.levels` to indicate how many quantiles to use. + +# Example directional analysis + +`{openair}` can plot basic wind roses very easily provided the variables `ws` (wind speed) and `wd` (wind direction) are available. + +```{r windrose} +windRose(mydata) +``` + +However, the real flexibility comes from being able to use the type option. + +```{r windrose2} +windRose(mydata, + type = "year", + layout = c(4, 2) +) +``` + +Wind roses summarising the wind conditions at a monitoring station per year, demonstrating the `{openair}` type option. + +There are many flavours of bivariate polar plots, as described [here](https://bookdown.org/david_carslaw/openair/sections/directional-analysis/polar-plots.html) that are useful for understanding air pollution sources. + +```{r polarplot} +polarPlot(mydata, + pollutant = "so2", + statistic = "cpf", + percentile = 90, + cols = "YlGnBu" +) +``` +