Skip to content

Instantly share code, notes, and snippets.

@halhen
Created July 8, 2017 18:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halhen/f6ee31c09d31733b9d73faed22b64b1c to your computer and use it in GitHub Desktop.
Save halhen/f6ee31c09d31733b9d73faed22b64b1c to your computer and use it in GitHub Desktop.
# Pasted from various sources and published quickly as part of a twitter discussion; not tested if this copy/paste actually runs.
# Result as https://twitter.com/hnrklndbrg/status/859888911337873409
library(tidyverse)
library(lubridate)
df.recent <- read_csv2('/home/henrik/private/vizyns/data/väder/göteborg-a-20170502.csv', skip=15) %>%
transmute(date=`Representativt dygn`,
min=as.numeric(`Lufttemperatur`),
max=as.numeric(`Lufttemperatur_1`))
df.old <- read_csv2('/home/henrik/private/vizyns/data/väder/göteborg-a-20161230.csv', skip=15) %>%
transmute(date=`Representativt dygn`,
min=as.numeric(`Lufttemperatur`),
max=as.numeric(`Lufttemperatur_1`))
df <- rbind(df.recent, df.old) %>%
mutate(year = year(date),
day_of_year = ymd(paste0('2000-', month(date), '-', day(date)))) %>%
arrange(year, day_of_year)
df %>%
filter(year >= 2000) %>%
#ggplot(aes(x=day_of_year, xend=day_of_year, yend=-year, y=-year + 0.05*max, group=year, color=max)) +
ggplot(aes(xmin=day_of_year, xmax=day_of_year+1, ymin=-year, ymax=-year + 0.06*max, y=-year + 0.06*max, group=year, fill=factor((max %/% 10)*10))) +
geom_rect() +
#geom_segment(size=1) +
geom_step(aes(day_of_year), color='white', size=0.2) +
scale_y_continuous(breaks=-2000:-2017, labels=abs) +
scale_x_date(date_breaks='1 month', date_labels='%b') +
labs(x="", y="", title="Temperatur i Göteborg", caption='Väderstation: Göteborg A\n@hnrklndbrg | Källa: SMHI') +
hrbrthemes::theme_ipsum(grid='') +
viridis::scale_fill_viridis(option='magma', discrete=TRUE, guide=guide_legend(reverse=TRUE), name='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment