Created
May 16, 2019 17:31
-
-
Save diegovalle/cc7568a4e057f683603dd0de487f95a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(aire.zmvm) | |
library(rsinaica) | |
library(ggplot2) | |
library(tidyverse) | |
library(lubridate) | |
library(zoo) | |
library(hrbrthemes) | |
pm25_2019 <- sinaica_param_data("PM2.5", "2019-05-01", "2019-05-16") | |
pm25 <- pm25_2019 %>% | |
filter(network_name %in% c("Valle de México", "Toluca", "Guadalajara", | |
"Cuernavaca", "Puebla", "Pachuca")) %>% | |
mutate(datetime = ymd_h(paste0(date, " ", hour))) %>% | |
group_by(network_name, station_name) %>% | |
arrange(station_id, date, hour) %>% | |
mutate(roll = rollapply(value, 24, mean, na.rm = TRUE, partial = 18, | |
fill = NA, align = "right")) | |
pm25$network_name <- factor(pm25$network_name, | |
levels = c("Cuernavaca", "Valle de México", "Toluca", | |
"Puebla", "Guadalajara", | |
"Pachuca")) | |
ggplot(pm25, | |
aes(datetime, roll, group = station_name)) + | |
geom_line() + | |
ylab("µg/m³") + | |
xlab("fecha") + | |
geom_hline(yintercept = 98, color = "#fc9272") + | |
annotate("text", y = 105, x = as.POSIXct("2019-05-05"), | |
label = "Contingencia en ZMVM", color = "#fc9272") + | |
labs(title = expression(paste("Promedio de 24 horas de niveles de ", PM[2.5], | |
", por ciudad y estación (2019-05-01 a 2019-05-16)")), | |
caption = "Fuenta: SINAICA") + | |
facet_wrap(~ network_name, ncol = 2) + | |
theme_ipsum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment