What does it do?

This package downloads pollution data for the Mexico City metro area. It can download real-time, daily maximum, minimum, or hourly average data for each of the pollution (and wind and temperature) measuring stations or geographical zones in the Zona Metropolitana del Valle de México.

Installation

For the moment this package is only available from github. For the development version:

if (!require(devtools)) {
    install.packages("devtools")
}
devtools::install_github('diegovalle/aire.zmvm')

Quick Example

The package consists mainly of three functions:

  • get_station_data downloads data for each of the pollution (and wind and temperature) measuring stations in the original measuring units.
  • get_zone_data downloads data for each of the 5 geographic zones of Mexico City as measured in IMECAs
  • get_latest_data downloads the latest and highest pollution value in IMECAs for each of the pollution measuring stations.
library("aire.zmvm")
library("dplyr")
library("ggplot2")
library("mgcv")
library("lubridate")
library("stringr")
library("gridExtra")
library("zoo")

# Download Ozone pollution data for all stations
o3 <- get_station_data(criterion = "MAXIMOS", # Can be one of MAXIMOS (daily maximum), 
                                                # MINIMOS (daily minimum), 
                                                # or HORARIOS (hourly average)
                       pollutant = "O3", # Can be one of "SO2", "CO", "NOX", "NO2", "NO", "O3", 
                                         # "PM10", "PM25", "WSP", "WDR", "TMP", "RH"
                       year = 2005:2017) # A numeric vector, the earliest year allowed is 1986

# Daily max among all base stations
o3_max <- o3 %>% 
  group_by(date) %>% 
  summarise(max = ifelse(all(is.na(value)),
                         NA,
                         base::max(value, na.rm = TRUE))) %>%
  na.omit()

# Plot the daily highest pm10 level with trendline
ggplot(o3_max, 
       aes(date, max, group = 1)) +
  geom_point(color = "black", size = .2, alpha = .4) +
  geom_smooth(method = "gam", formula = y ~ s(x, k = 25)) +
  labs(title = "Daily maximum O3 levels",
       subtitle = "On July 2015 the supreme court overturned a rule banning all cars more than eight years old from the\n'hoy no circula' program") +
  ylab("maximum daily O3 value in ppb") +
  xlab("date") +
  geom_vline(xintercept = as.numeric(as.Date("2015-07-01"))) +
  annotate("text", label = "supreme court ruling", 
           x = as.Date("2014-01-20"),
           y = 350) +
  theme_bw()