Skip to content

Instantly share code, notes, and snippets.

@diegovalle
Last active May 15, 2019 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegovalle/3c0719d08b191e2f0e92a85a144b6287 to your computer and use it in GitHub Desktop.
Save diegovalle/3c0719d08b191e2f0e92a85a144b6287 to your computer and use it in GitHub Desktop.
library(lubridate)
library(aire.zmvm)
library(ggplot2)
library(dplyr)
library(hrbrthemes)
get_latest_imeca()
df <- get_zone_imeca("HORARIOS", "TC", "TZ", "2019-05-01", "2019-05-14")
df$datetime <- ymd_h(paste0(df$date, " ", df$hour))
df <- df %>%
filter(pollutant %in% c("O3", "PM25")) %>%
group_by(datetime, pollutant) %>%
summarise(max = max(value))
ggplot(df, aes(datetime, max)) +
geom_line() +
facet_wrap(~pollutant) +
ylab("IMECA") +
geom_hline(yintercept = 151, color = "#fc9272") +
annotate("text", y = 160, x = as.POSIXct("2019-05-10"), label = "Contingencia") +
xlab("fecha y hora") +
labs(title = expression(paste("Máximos horarios de ", O[3], " y ", PM[2.5]))) +
theme_ft_rc()
df <- get_zone_imeca("MAXIMOS", "PM25", "TZ", "2009-01-01", "2019-05-14")
df <- df %>%
group_by(date) %>%
summarise(max = max(value))
ggplot(df, aes(date, max)) +
geom_line(size = .3) +
ylab("IMECA") +
geom_smooth() +
geom_hline(yintercept = 151, color = "#fc9272") +
annotate("text", y = 155, x = as.Date("2018-05-10"), label = "151 puntos", color = "#fc9272") +
xlab("fecha") +
labs(title = expression(paste("Máximos diarios de ", PM[2.5], " (2009-2019)"))) +
theme_ft_rc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment