Last active
February 1, 2018 15:46
-
-
Save diegovalle/79f0268ead2bc5ba8d9ae5851606b0c4 to your computer and use it in GitHub Desktop.
Temperaturas diarias durante eneros de 2005 a 2018 por estación
This file contains 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
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) | |
temp$day <- str_c(day(temp$date), " - ", temp$month) | |
temp$ymdh <- ymd_h(str_c(temp$date, " ", temp$hour)) | |
# remove stations that always report 0 | |
temp <- temp %>% | |
group_by(year, station_code) %>% | |
filter(!sum(value, na.rm = TRUE) == 0) | |
temp_morning <- filter(temp, hour %in% c(1:12)) | |
ggplot(temp_morning, aes(month, value, group = month)) + | |
geom_jitter(alpha = .2) + | |
geom_boxplot() + | |
coord_flip() | |
temp_morning$color <- "otros días" | |
temp_morning$color[which(temp_morning$date == "2018-01-30")] <- "enero 30-31, 2018" | |
temp_morning$color[which(temp_morning$date == "2018-01-31")] <- "enero 30-31, 2018" | |
temp_morning$size <- .1 | |
temp_morning$size[which(temp_morning$date == "2018-01-30")] <- .1 | |
temp_morning$size[which(temp_morning$date == "2018-01-31")] <- .1 | |
temp_morning$hour <- factor(temp_morning$hour, levels = c(1:12)) | |
# remove the stations that didn't report data January 30-31, 2018 | |
temp_morning <- temp_morning %>% | |
group_by(station_code) %>% | |
arrange(desc(value)) %>% | |
filter(sum(value[date == "2018-01-30"], na.rm = TRUE) > 0 | | |
sum(value[date == "2018-01-31"], na.rm = TRUE) > 0) %>% | |
ungroup() | |
temp_morning <- mutate(temp_morning, | |
station_code = reorder(station_code, value, min, na.rm = TRUE)) | |
ggplot(temp_morning, aes(hour, value, group = day, color = color)) + | |
geom_line(alpha = .5, size = .7) + | |
facet_wrap(~station_code) + | |
scale_colour_manual("día", values = c("#542788", "#fdb863")) + | |
scale_x_discrete(breaks = c(1, 6, 12), labels = c("1:00 AM", "6:00 AM", "12:00 PM")) + | |
xlab("hora del día") + | |
ylab("temperatura[°C]") + | |
ggtitle("Temperaturas diarias durante las mañanas de enero de 2005 a 2018 por estación en CDMX", | |
subtitle = "Fuente: SEDEMA") + | |
theme_bw() + | |
theme(axis.text.x = element_text(angle = 70, hjust = 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment