Skip to content

Instantly share code, notes, and snippets.

@diegovalle diegovalle/january-temps.R
Last active Jan 31, 2018

Embed
What would you like to do?
Hourly January temperatures for all reporting sensors for 2016-2018
#based on https://cran.r-project.org/web/packages/ggjoy/vignettes/gallery.html
library(viridis)
library(ggridges)
library(aire.zmvm)
library(lubridate)
library(ggplot2)
library(dplyr)
library(tidyr)
library(stringr)
library(lubridate)
temp <- data.frame()
for (year in 2005:2018) {
df2 <- get_station_single_month("TMP", year, 1)
temp <- rbind(temp, df2)
}
temp$month <- months(temp$date)
temp$month <- factor(temp$month, levels = rev(unique(temp$month)) )
temp$month <- str_c(temp$month, " - ", year(temp$date))
temp$year <- year(temp$date)
# remove stations that always report 0
temp <- temp %>%
group_by(year, station_code) %>%
filter(!sum(value, na.rm = TRUE) == 0)
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. [C]", option = "C") +
labs(title = 'January Temperatures in Mexico city',
subtitle = 'Hourly January temperatures for all reporting sensors 2005-2018\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.