Home/Blog/The openair Package in R: A Practical Guide for Air Quality Data
Back to Blog

The openair Package in R: A Practical Guide for Air Quality Data

August 27, 2026
8 min read
By DSTechnoverse
Air Quality Analysis

openair turns air quality analyses that take fifty lines of general-purpose code into one line each. A tour of the functions that matter — windRose, polarPlot, timeVariation, TheilSen and calendarPlot — with what each actually tells you.

The openair Package in R: A Practical Guide for Air Quality Data

Most air quality analysis is the same handful of questions asked repeatedly: where is it coming from, when does it happen, is it getting better, and how often do we breach the limit. openair answers each in roughly one line.

What openair Is

An R package written specifically for air quality data analysis, developed in the UK research community and used widely in regulatory and academic work. Its value is not that it does things other tools cannot — it is that the domain conventions are already built in.

install.packages("openair")
library(openair)
library(dplyr)

The Data Format It Expects

openair is opinionated about column names, and following the convention saves constant argument-passing:

ColumnMeaning
datePOSIXct timestamp — must be this name
wsWind speed, m/s
wdWind direction, degrees from north
pm25, pm10, no2, so2, o3Pollutant concentrations
siteStation identifier, for multi-site work
aq <- read.csv("station.csv") |>
  mutate(date = as.POSIXct(datetime, format = "%d-%m-%Y %H:%M", tz = "Asia/Kolkata"))

Set the timezone explicitly. Leaving it to the system locale is how an analysis becomes irreproducible on someone else's machine.

summaryPlot — Always Run This First

summaryPlot(aq)

Produces, for every variable at once: a time series, a histogram, and — most usefully — a visual map of missing data.

Run it before anything else. It answers "how bad is this dataset" in one glance, and it routinely reveals a three-month instrument outage that would otherwise have been silently averaged over.

windRose and pollutionRose — Where Is It Coming From?

windRose(aq)
pollutionRose(aq, pollutant = "pm25")

windRose shows the frequency of wind by speed and direction — the meteorological context.

pollutionRose is the more useful one. It weights each direction by pollutant concentration, so a long arm points at a direction that brings high pollution. That is a source-direction indicator, not merely a wind statistic.

The distinction matters: a direction can be rare but consistently dirty. windRose shows it as a stub; pollutionRose shows it as a problem.

polarPlot — The Most Informative Single Plot

polarPlot(aq, pollutant = "pm25")

Concentration as a surface over wind speed and direction. Reading it:

PatternInterpretation
Hot spot near the centreLocal ground-level source; concentration falls as wind rises
Hot spot at high wind speed, one directionDistant or elevated source, transported in
Uniform ringRegional background rather than a local source
Sharp narrow armA specific, identifiable source in that bearing

For source attribution this single plot is often worth more than a chapter of description. It pairs naturally with formal source apportionment.

timeVariation — Four Diagnostics at Once

timeVariation(aq, pollutant = c("pm25", "no2"))

Returns diurnal, day-of-week, monthly and hour-by-weekday panels, with confidence intervals.

The confidence intervals are the part people ignore and should not. A visually striking diurnal peak with overlapping intervals is not a reliable pattern, and openair draws them so you can tell.

Interpretation shortcuts:

  • Twin morning and evening peaks, weaker at weekends → traffic
  • Flat overnight, sharp post-dawn rise → boundary-layer mixing, not emissions
  • Elevated at night → nocturnal inversion trapping a steady source
  • No weekday/weekend difference → non-anthropogenic or continuous industrial source

calendarPlot — Exceedances at a Glance

calendarPlot(aq, pollutant = "pm25", year = 2025)

A calendar heatmap of daily values. Immediately shows whether exceedances cluster in winter, scatter randomly, or concentrate around specific events.

For Indian datasets this usually renders the winter inversion season and the post-Diwali period unmistakably, which is far more persuasive in a report than the same fact stated in prose.

TheilSen — Trends, Properly

TheilSen(aq, pollutant = "pm25", deseason = TRUE)

Runs a Theil-Sen slope estimate with Mann-Kendall significance, and deseason = TRUE removes the seasonal cycle first.

Why not linear regression: air quality data is skewed and gappy, which violates regression's assumptions. Theil-Sen takes the median of all pairwise slopes and is robust to both.

The output gives slope in units per year with a confidence interval and significance stars. Report all three — a slope without its interval overstates certainty. See air quality trend analysis methods.

Other Functions Worth Knowing

FunctionAnswers
timePlotHow do several pollutants move together?
scatterPlotAre two variables related, with a smoother
trendLevelHeatmap of concentration by hour and month
percentileRoseHow do high percentiles vary by direction?
smoothTrendNon-linear trend, where a straight line is wrong
selectByDateSubset by year, month, weekday or hour
rollingMean8-hour rolling means for ozone standards
corPlotCorrelation matrix across pollutants

rollingMean deserves a note: ozone and carbon monoxide standards are defined on rolling averages, not clock-hour blocks. Computing them by simple resampling gives the wrong answer.

A Complete Short Analysis

library(openair)
library(dplyr)

aq <- read.csv("station.csv") |>
  mutate(date = as.POSIXct(datetime, format = "%d-%m-%Y %H:%M", tz = "Asia/Kolkata"))

summaryPlot(aq)                                     # 1. how bad is the data
pollutionRose(aq, pollutant = "pm25")               # 2. which direction
polarPlot(aq, pollutant = "pm25")                   # 3. what kind of source
timeVariation(aq, pollutant = "pm25")               # 4. when
calendarPlot(aq, pollutant = "pm25", year = 2025)   # 5. which days breached
TheilSen(aq, pollutant = "pm25", deseason = TRUE)   # 6. is it improving

Six lines covering source direction, source character, temporal behaviour, exceedance pattern and long-term trend. Reproducing that in general-purpose plotting code is a day's work.

Conditioning: The Argument That Multiplies Everything

Nearly every openair function takes a type argument, which splits the plot into panels by another variable. This is where the package earns its reputation.

polarPlot(aq, pollutant = "pm25", type = "season")
timeVariation(aq, pollutant = "pm25", type = "weekday")
calendarPlot(aq, pollutant = "pm25", type = "year")

Useful conditioning variables:

type valueSplits byReveals
"season"Meteorological seasonWhether a source is seasonal
"year"Calendar yearWhether a source appeared or stopped
"weekday"Day of weekAnthropogenic versus continuous
"daylight"Day and nightBoundary-layer versus emissions effects
"site"StationSpatial contrast
"ws"Wind speed bandLocal versus transported

The single most diagnostic use is polarPlot(..., type = "season"). A source that appears only in winter behaves differently from one present year-round, and splitting by season separates a genuine emitter from an inversion artefact — a distinction that a combined plot hides completely.

You can also condition on your own column. Adding a period column marked "before" and "after" an intervention, then plotting with type = "period", produces a direct visual before-and-after on identical axes.

Limitations

It is R-only. No Python equivalent covers the same ground.

It assumes hourly data in most functions. Sub-hourly needs aggregation first.

Plot customisation is constrained. The lattice-based output is harder to restyle than ggplot2. For publication figures you may extract the data and re-plot.

It will not clean your data. Validity flags, range checks and capture rules remain your responsibility — see Python for air quality data analysis and air quality monitoring data QA/QC.

Getting Data Out of openair

Plots are useful; the numbers behind them are what goes into a report. Most openair functions return the computed data invisibly, and capturing it saves recomputing the same statistic by hand.

Assigning the result of a function gives you an object whose data element holds the values used to draw the plot. For TheilSen this is the slope, the confidence interval and the p-value per pollutant — exactly the three figures a trend statement needs. For timeVariation it is the hourly, weekly and monthly means with their confidence limits.

Two practical uses. First, report the numbers, not just the picture — a trend chart with "slope −2.4 µg/m³ per year, 95% CI −3.1 to −1.6" in the caption is far more defensible than the chart alone. Second, re-plot in ggplot2 when you need publication styling that openair's lattice output cannot easily produce; you keep the domain-correct calculation and gain full control of the appearance.

It also makes results testable. A script that extracts the slope and asserts it against a previously recorded value will catch the day a data refresh silently changes a headline finding.

Frequently Asked Questions

Is openair free? Yes, open source on CRAN.

Do I need to know R well? No. The functions take a data frame and a pollutant name. Basic data loading is enough to get value from it.

Why must the date column be called date? It is the package convention. Renaming your column is simpler than passing arguments everywhere.

Can I use it without wind data? Yes for timeVariation, calendarPlot, TheilSen and summaryPlot. The rose and polar functions require ws and wd.

How do I handle multiple monitoring sites? Add a site column and use the type = "site" argument to facet most functions by station.

Does it work with CPCB data? Yes, once parsed and renamed to the convention. See CAAQMS data analysis.

Is Theil-Sen better than linear regression here? For air quality data, generally yes — it does not assume normality and tolerates gaps and outliers. See the Theil-Sen slope estimator.


Need air quality data analysed properly? DSTechnoverse handles monitoring data QA/QC, statistical analysis, trend testing and compliance reporting in R and Python. We are based in Indore, Madhya Pradesh and work with clients across India. See our air quality analysis and EIA data analysis outsourcing services, or talk to our team.

Share

Tags

openair R packageopenair tutorialR air quality analysiswind rose Rpolar plot air qualityTheilSen openairtimeVariation

Explore More Articles

Discover more insights and updates from DSTechnoverse

View All Articles