Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#based on https://cran.r-project.org/web/packages/ggjoy/vignettes/gallery.html
library(viridis)
library(ggridges)
#devtools::install_github('diegovalle/aire.zmvm')
library(aire.zmvm)
library(lubridate)
library(ggplot2)
library(dplyr)
library(tidyr)
temp <- get_station_data(criterion = "HORARIOS", # Can be one of MAXIMOS (daily maximum),
# MINIMOS (daily minimum),
# or HORARIOS (hourly average)
pollutant = "TMP", # Can be one of "SO2", "CO", "NOX", "NO2", "NO", "O3",
# "PM10", "PM25", "WSP", "WDR", "TMP", "RH"
year = 2016) # A numeric vector, the earliest year allowed is 1986
temp$month <- months(temp$date)
temp$month <- factor(temp$month, levels = rev(unique(temp$month)) )
#remove stations that always report 0
temp <- temp %>%
spread(station_code, value)
temp <- temp[, colSums(temp != 0, na.rm = TRUE) > 0]
temp <- gather(temp, station_code, value, ACO:XAL)
max(temp$value, na.rm = TRUE)
ggplot(temp, aes(x = value, y = month, fill = ..x..)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01, gradient_lwd = 1.) +
scale_x_continuous(expand = c(0.01, 0)) +
scale_y_discrete(expand = c(0.01, 0)) +
scale_fill_viridis(name = "Temp. [F]", option = "C") +
labs(title = 'Temperatures in CDMX',
subtitle = 'Hourly temperatures for all reporting sensors by month for 2016\nSource: SEDEMA') +
theme_ridges(font_size = 13, grid = TRUE) + theme(axis.title.y = element_blank())
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.