Last active
August 14, 2018 16:37
-
-
Save mschnetzer/150b8e598cbfae8316f2ec52fa064e67 to your computer and use it in GitHub Desktop.
Häuser- und Wohnungspreise 2010-2017 (https://twitter.com/matschnetzer/status/1017287439084343296)
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(eurostat) | |
library(ggmap) | |
library(msthemes) | |
# Get Eurostat data and calculate diff 2010-2017 | |
data <- get_eurostat("prc_hpi_a",filters=list(typpurch="TOTAL",unit="INX_A_AVG",time=c(2010,2017)),type="code",time_format="num") %>% | |
select(geo,time,values) %>% group_by(geo) %>% mutate(inc=(values-lag(values))/lag(values)*100) %>% filter(!is.na(inc)) %>% select(geo,inc) | |
# Create categories for changes in house prices | |
mapdat <- data %>% filter(!geo %in% c("EU","EA")) %>% | |
mutate(cat = cut(inc,breaks = seq(-20, 80, by = 20))) %>% select(geo,cat) %>% | |
mutate(cat=recode(cat,"(-20,0]"=" -20-0%","(0,20]"=" >0-20%","(20,40]"=" >20-40%","(40,60]"=" >40-60%","(60,80]"=" >60-80%")) | |
# Get Eurostat mapping data | |
map <- get_eurostat_geospatial(output_class = "df", resolution = "60", nuts_level = 0) | |
eumap <- left_join(map,mapdat,by = c("NUTS_ID" = "geo")) %>% filter(!is.na(cat)) | |
# Load google map and get rid off borders and country labels | |
google.map <- get_googlemap(center="Europe", zoom=3, maptype="roadmap",crop = TRUE, | |
style = c(c(feature="all",element="geometry.stroke",visibility="off"), | |
c("&style=",feature="all",element="labels",visibility="off"))) | |
# Create custom palette | |
pal_coolhot <- c("#2389da","#ffb9b9","#ee7272","#a31818","#6d0202") | |
# Plot map | |
ggmap(google.map) + geom_polygon(aes(fill=cat,x=long,y=lat,group=group), | |
data=eumap,alpha=0.8,color = "black", size=0.2) + | |
scale_x_continuous(limits = c(-17, 37)) + | |
scale_y_continuous(limits = c(36, 71.5)) + | |
scale_fill_manual(values=pal_coolhot) + theme_ms_line(grid=FALSE) + | |
theme(axis.title = element_blank(),axis.text=element_blank(), | |
legend.title = element_blank(),legend.position=c(0.2,0.8), | |
legend.box.background = element_rect(colour = "black")) + | |
labs(title="Wohnen in Österreich wurde deutlich teurer",subtitle="Entwicklung der Häuser- und Wohnungspreise 2010-2017", | |
caption="Quelle: EUROSTAT. Grafik: @matschnetzer") + | |
ggsave("hauspreise.png", width=6,height=6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment