Created
September 6, 2018 16:45
-
-
Save turgeonmaxime/7ed3768a930ec9ec2078f33836fdcd74 to your computer and use it in GitHub Desktop.
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(tidyverse) | |
library(lubridate) | |
library(weathercan) | |
# Lethbridge and Saskatoon | |
data <- weather_dl(station_ids = c(2265, 50091), | |
start = "2012-01-01", end = "2018-08-15") | |
# Plot full data | |
data %>% | |
ggplot(aes(x = time, y = temp, group = station_name, | |
colour = station_name)) + | |
theme_bw() + | |
geom_line() | |
# Plot mid-September to mid-October from multiple years | |
data %>% | |
filter(month %in% c("09", "10")) %>% | |
mutate(time = ymd_hm(paste0("2018-", strftime(time, format = "%m-%d %H-%M")))) %>% | |
filter(time >= ymd("20180915"), time <= ymd("20181015")) %>% | |
mutate(grp = paste0(station_name, year)) %>% | |
mutate(snow = str_detect(weather, "(s|S)now"), | |
snow = if_else(is.na(snow), FALSE, snow), | |
snow = factor(as.numeric(snow))) %>% | |
ggplot(aes(x = time, y = temp)) + | |
theme_bw() + | |
geom_line(aes(group = grp, colour = station_name)) + | |
theme(legend.position = 'top') + | |
geom_point(aes(size = snow)) + | |
scale_size_manual(values = c(0, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment