Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
Last active July 18, 2022 09:40
Show Gist options
  • Save mschnetzer/ea0bba2c0e22ff119616ec77e33cb0aa to your computer and use it in GitHub Desktop.
Save mschnetzer/ea0bba2c0e22ff119616ec77e33cb0aa to your computer and use it in GitHub Desktop.
Anzahl der Hitzetage in Wien und Österreich (https://twitter.com/matschnetzer/status/1548947293889511424)
library(tidyverse)
library(lubridate)
library(msthemes)
library(geojsonsf)
library(sf)
# Get data: https://dataset.api.hub.zamg.ac.at/app/station-new/historical/klima-v1-1d?anonymous=true
tempdat <- read.csv("TAG Datensatz_19500101_20211231.csv") %>%
mutate(name = case_when(
station == 105 ~ "Wien",
station == 131 ~ "Salzburg",
station == 93 ~ "Niederösterreich",
station == 56 ~ "Oberösterreich",
station == 48 ~ "Kärnten",
station == 39 ~ "Tirol",
station == 30 ~ "Steiermark",
station == 22 ~ "Burgenland",
station == 15 ~ "Vorarlberg"
))
blmap <- geojson_sf("https://raw.githubusercontent.com/ginseng666/GeoJSON-TopoJSON-Austria/master/2021/simplified-95/laender_95_geo.json")
findat <- tempdat %>% mutate(time = ymd(time)) %>%
group_by(year(time), name, .drop = FALSE) %>%
filter(tmax >= 30) %>% count() %>%
rename(year = `year(time)`)
plotdat <- blmap %>% left_join(findat)
plotdat %>% ggplot(aes(fill = n)) +
facet_wrap(~year, ncol = 10) +
geom_sf(size = 0.05, color = "black") +
scale_fill_gradient(low = "white", high = "red", name = "Anzahl Hitzetage") +
guides(fill = guide_colorbar(direction = "horizontal", barheight = 0.5,
barwidth = 10, title.position = "top")) +
labs(title = "Hitzetage in Österreich",
subtitle = "Anzahl der Tage mit 30°C oder wärmer nach Bundesland",
caption = "Anm.: Messdaten der jeweiligen Landeshauptstadt\nQuelle: ZAMG. Grafik: @matschnetzer") +
theme_ms(grid = F, alttf = T) +
theme(axis.text = element_blank(),
strip.text = element_text(size = 7, family = "Raleway"),
legend.position = "none")
ggsave("hitzetage.png", width = 8, height = 5, dpi = 320)
# Vienna only
wien <- blmap %>% filter(name == "Wien")
wiendat <- findat %>% filter(name == "Wien")
wienplot <- wien %>% left_join(wiendat)
wienplot %>% ggplot(aes(fill = n)) +
facet_wrap(~year, ncol = 10) +
geom_sf(size = 0.05, color = "black") +
geom_text(aes(x=16.37505, y= 48.20915, label = n), size = 5, family = "Hack",
fontface = "bold", color = "white", alpha = 0.8) +
scale_fill_gradient(low = "grey90", high = "red", name = "Anzahl Hitzetage") +
guides(fill = guide_colorbar(direction = "horizontal", barheight = 0.5,
barwidth = 10, title.position = "top")) +
labs(title = "Hitzetage in Wien",
x=NULL, y=NULL,
subtitle = "Anzahl der Tage mit 30°C oder wärmer",
caption = "Anm.: Messdaten der Hohen Warte\nQuelle: ZAMG. Grafik: @matschnetzer") +
theme_ms(grid = F, alttf = T) +
theme(axis.text = element_blank(),
strip.text = element_text(size = 7, family = "Raleway"),
legend.position = "none")
ggsave("hitzetagewien.png", width = 7, height = 6, dpi = 320)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment