Skip to content

Instantly share code, notes, and snippets.

@diegovalle
Last active May 16, 2019 17:22
Show Gist options
  • Save diegovalle/bb42e8c6249490d1e864ea4adf27c31a to your computer and use it in GitHub Desktop.
Save diegovalle/bb42e8c6249490d1e864ea4adf27c31a to your computer and use it in GitHub Desktop.
library(aire.zmvm) #devtools::install_github('diegovalle/aire.zmvm')
library(ggplot2)
library(tidyverse)
library(lubridate)
library(zoo)
library(hrbrthemes)
df <- get_station_month_data("HORARIOS", "PM25", 2019, 5)
df <- df %>%
filter(station_code %in% c("SAC", "NEZ")) %>%
mutate(datetime = ymd_h(paste0(date, " ", hour))) %>%
group_by(station_code) %>%
arrange(station_code, date, hour) %>%
mutate(roll = rollapply(value, 24, mean, na.rm = TRUE, partial = 18,
fill = NA, align = "right"))
convert_to_imeca(98, "PM25")
df$station_code <- factor(df$station_code,
levels = c("SAC", "NEZ"))
ggplot(df, aes(datetime, roll)) +
geom_line(color = "#2b8cbe") +
geom_line(aes(datetime, value), color = "gray") +
facet_wrap(~ station_code) +
annotate("text", y = 105, x = as.POSIXct("2019-05-05"), label = "Contingencia") +
geom_hline(yintercept = 98, color = "#fc9272") +
ylab("µg/m³") +
xlab("fecha") +
labs(title = expression(paste("Niveles de ", PM[2.5], " y promedio de 24 horas",
" para las estaciones SAC y NEZ")),
subtitle = "El promedio de 24 horas de 98 µg/m³ es equivalente a 151 IMECA",
caption = "Fuente: aire.cdmx.gob.mx") +
theme_ipsum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment