-
Notifications
You must be signed in to change notification settings - Fork 17
/
23-tiles-house-prices.R
92 lines (83 loc) · 3.46 KB
/
23-tiles-house-prices.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
library(tidyverse)
library(lubridate)
library(here)
library(ggtext)
library(geofacet)
base_path <- here("2022", "23")
#' Source: Eurostat
#' House price index (2015 = 100) - quarterly data
#' online data code: PRC_HPI_Q
#' Download TSV full dataset
df_raw <- read_tsv(here(base_path, "prc_hpi_q_tabular.tsv"),
na = c(":", ": c"))
#' purchases:
#' DW_EXST ... of existing dwellings
#' DW_NEW ... of new dwellings
#' TOTAL
#'
#' unit of measure:
#' I10_Q Index 2010 = 100
#' I15_Q Index 2015 = 100
#' RCH_A_AVG Annual average rate of change
df <- df_raw %>%
separate(1, into = c("freq", "purchase", "unit", "region"), sep = ",") %>%
select(-freq) %>%
pivot_longer(cols = -c("purchase", "unit", "region"), names_to = "quarter") %>%
mutate(year_quarter_date = zoo::as.Date(zoo::as.yearqtr(quarter, format = "%Y-Q%q")),
country = countrycode::countrycode(region, "iso2c", "country.name"),
value = as.numeric(value)) %>%
# replace missing values with the value from the previous quarter
group_by(purchase, unit, region) %>%
fill(value, .direction = "down") %>%
ungroup() %>%
filter(year(year_quarter_date) >= 2010) %>%
filter(!is.na(country))
# Edit the geofacet grid
europe_grid <- europe_countries_grid1 %>%
filter(name %in% unique(df$country), !name %in% c("Turkey", "Switzerland"))
p <- df %>%
filter(purchase == "TOTAL", unit == "I10_Q") %>%
ggplot(aes(year_quarter_date, y = 1)) +
geom_tile(aes(fill = value), col = NA, size = 0) +
geom_label(
data = . %>% filter(quarter == "2016-Q1"),
aes(label = country), stat = "unique", color = "black",
size = 3, fill = "#FFFFFFBB", family = "Fira Sans Condensed SemiBold",
label.size = 0, label.r = unit(1, "mm")) +
scale_fill_viridis_c() +
facet_geo(vars(country), grid = europe_grid, label = "name") +
guides(fill = guide_colorbar(title.position = "top")) +
labs(
title = "Housing Prices Rising in many European Countries",
subtitle = "The House Price Index (HPI) measures inflation in the residential
property market.
The HPI captures price changes of all kinds of residential property purchased
by households (flats, detached houses, terraced houses, etc.), both new and
existing. Only market prices are considered, self-build dwellings are therefore
excluded.
The land component of the residential property is included.
",
caption = "**Source:** Eurostat. **Visualization:** Ansgar Wolsing",
fill = "Annual average index<br>*(2010=100)*") +
theme_void(base_family = "Fira Sans Condensed") +
theme(
plot.background = element_rect(color = NA, fill = "grey87"),
panel.background = element_rect(color = "white"),
text = element_text(color = "grey10"),
plot.title = element_text(
family = "Fira Sans Condensed SemiBold", color = "black",
hjust = 0, size = 24, margin = margin(b = 8)),
plot.subtitle = element_textbox(
width = 0.8, hjust = 0, halign = 0, lineheight = 1.2,
margin = margin(b = 24)),
plot.caption = element_markdown(margin = margin(t = 18)),
strip.text = element_blank(),
plot.margin = margin(12, 12, 12, 12),
legend.direction = "horizontal",
legend.position = c(0.9, 0.95),
legend.title = element_markdown(hjust = 0.5, lineheight = 1),
legend.key.width = unit(8, "mm"),
legend.key.height = unit(3, "mm"),
panel.spacing.y = unit(4, "mm")
)
ggsave(here(base_path, "23-titles-europe-housing-prices.png"), width = 9, height = 8)