-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
127 lines (97 loc) · 3.49 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# airparis
<!-- badges: start -->
<!-- badges: end -->
Package `airparis` is providing a small set of functions to access data about air quality in Ile-de-France
provided by [Airparif](https://www.airparif.asso.fr/).
```{r echo=FALSE, fig.height=2, message=FALSE}
library(airparis)
library(tidyverse)
library(ggiraph)
library(lubridate)
library(glue)
change_dayinweek <- function(x){
x[x %in% 1] <- 8
x
}
data <- read_atmo() %>%
mutate(isoweek = isoweek(date_time),
isoyear = isoyear(date_time),
weekday = change_dayinweek(wday(date_time)),
daylabel = weekdays(date_time),
classification = cut( score, breaks = c(0, 4.5, 7.5, Inf), labels = c("Bon", "Mediocre", "Mauvais")),
tooltip = glue("{daylabel} {date_time}\nindice {score}\nclassification: {classification}")
)
weektoadd <- data %>% filter(isoyear == min(isoyear)) %>%
arrange(desc(isoweek)) %>%
slice(1) %>% pull(isoweek)
data <- mutate(
data,
weekid = case_when(
isoyear == min(isoyear) ~ isoweek,
TRUE ~ isoweek + weektoadd)
)
P <- ggplot(data, aes(weekid, weekday, fill = classification, tooltip = tooltip)) +
geom_tile_interactive(colour = "white") +
coord_equal() +
scale_y_reverse() +
scale_fill_manual_interactive(name = "",
values = c("Bon" = "#84bf75", "Mediocre" = "#f29400", "Mauvais" = "#d82517"),
tooltip = c("Bon" = "1 <= indice <= 4", "Mediocre" = "5 <= indice <= 7", "Mauvais" = "8 <= indice <= 10")) +
theme_void() +
theme(legend.position = "bottom",
legend.key.size = unit(0.25, "cm") ) +
labs(title = "ATMO index")
girafe(ggobj = P, width_svg = 6, height_svg = 2) %>%
girafe_options(opts_zoom(max = 3), opts_toolbar(position = "top"))
```
Users can retrieve hourly and daily data measured in Ile-de-France with function
`read_measures()`. The following pollutants are available:
* `o3`: ozone
* `pm10`: Particulate matter with a diameter of 10 micrometers or less
* `pm25`: Particulate matter with a diameter of 2.5 micrometers or less
* `nox`: Nitrogen oxide
* `no2`: Nitrogen dioxide
```{r}
library(airparis)
read_measures(pollutant = "pm10", station_id = "4181",
dt_start = as.Date("2019-06-01"), dt_end = as.Date("2019-06-04"),
granularity = "day")
```
The stations where measures are made are available in dataset `stations`:
```{r}
utils::head( stations )
```
Function `read_atmo()` read ATMO index and return them in a data.frame.
The data is only containing the last year of daily historic. The air quality
index ranges from 1 (very good) to 10 (very bad). It characterizes in a simple
and comprehensive way the air quality of an urban agglomeration.
It is not possible to reproduce exact calculations as so2 is not available
through the web service or with read_measures().
```{r}
utils::tail( read_atmo() )
```
Function `read_alert()` read air quality alerts issued by airparif.
```{r}
utils::tail( read_alert() )
```
Pollutants emissions are available for 2015 as data.frame (see `emissions_epci`, `emissions_region`, `emissions_departement`):
```{r}
utils::head( emissions_epci )
```
## Installation
You can install the development version of airparis from [github](https://github.com/ardata-fr/airparis) with:
``` r
remotes::install_github("ardata-fr/airparis")
```