Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.