Skip to content

Instantly share code, notes, and snippets.

@diegovalle
Created January 3, 2019 18:09
Show Gist options
  • Save diegovalle/151fc7446769c64fe0eb0e42e3694052 to your computer and use it in GitHub Desktop.
Save diegovalle/151fc7446769c64fe0eb0e42e3694052 to your computer and use it in GitHub Desktop.
library(rsinaica)
library(dplyr)
library(zoo)
library(gghighlight)
df_pm25 <- sinaica_param_data("PM2.5", "2018-12-23", "2019-01-02")
df_pm10 <- sinaica_param_data("PM10", "2018-12-23", "2019-01-02")
plot_top <- function(df, title = "", ylab = "", exclude = c("")) {
df_max <- df %>%
filter(!network_name %in% exclude) %>%
group_by(station_id, network_name) %>%
arrange(station_id, date, hour) %>%
mutate(roll24 = rollapply(value, 24, mean, na.rm = TRUE, partial = 18,
fill = NA, align = "right")) %>%
ungroup() %>%
#summarise(mean = mean(value, na.rm = TRUE)) %>%
group_by(date, network_name) %>%
summarise(max = max(roll24, na.rm = TRUE)) %>%
ungroup()
gghighlight_line(df_max, aes(as.Date(date), max,
group = network_name, color = network_name),
max(max, na.rm = TRUE), max_highlight = 7) +
theme_bw() +
ggtitle(title) +
xlab("date") +
ylab(ylab)
}
plot_top(df_pm10,
title = expression(paste("Pollution measuring network with the highest ",
PM[10], " pollution values Dec 23 to Jan 02")),
ylab =expression(paste(PM[10], " ", mu,"g/", m^3)),
c("Saltillo", "Tepeapulco"))
plot_top(df_pm25,
title = expression(paste("Pollution measuring network with the highest ",
PM[2.5], " pollution values Dec 23 to Jan 02")),
ylab =expression(paste(PM[2.5], " ", mu,"g/", m^3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment