-
-
Save fmacias64/551db7ff9c73457a75c21a2b9c5e4752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #based on https://cran.r-project.org/web/packages/ggjoy/vignettes/gallery.html | |
| library(viridis) | |
| library(ggjoy) | |
| 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_joy_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_joy(font_size = 13, grid = TRUE) + theme(axis.title.y = element_blank()) | |
| geom_joy_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. [C]", option = "C") + | |
| labs(title = 'Temperatures in CDMX', | |
| subtitle = 'Temperatures for all reporting sensors by month for 2016\nSource: SEDEMA') + | |
| theme_joy(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