Last active
February 26, 2022 10:41
-
-
Save mhermans/a0ebe226cc8922675a3255fe65085e96 to your computer and use it in GitHub Desktop.
Visualise barchart of offshore wealth, using gghighlight and ggtext to call out countries and directly label values
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
country_name_en | country_name_nl | offshore_total_gpd_pct | offshore_swiss_gpd_pct | offshore_nonswiss_gpd_pct | offshore_nonswiss_caribbean_gpd_pct | offshore_nonswiss_asia_gpd_pct | offshore_nonswiss_eu_gpd_pct | |
---|---|---|---|---|---|---|---|---|
Albania | Albanië | 0.009099364830022943 | 0.003902763756464408 | 0.005196601073558535 | 0 | 0 | 0.005196601060415357 | |
Austria | Oostenrijk | 0.0788387199205287 | 0.053434090107880305 | 0.025404629812648388 | 5.020665119495822e-4 | 0.007873792222186092 | 0.017028771190398466 | |
Belgium | België | 0.1737783533244881 | 0.10349841462526806 | 0.07027993869922006 | 8.952427068932938e-4 | 0.002173648870789221 | 0.06721104507451295 | |
Bosnia and Herzegovina | Bosnië en Herzegovina | 0.050279356187570394 | 0.038434908810615606 | 0.011844447376954786 | 0 | 0 | 0.011844446974824816 | |
Bulgaria | Bulgarije | 0.041259899174114475 | 0.03265272313968249 | 0.008607176034431991 | 7.028093556917629e-5 | 6.035926334904682e-5 | 0.008476535463362765 | |
Croatia | Kroatië | 0.052318515832664274 | 0.03587663695040035 | 0.016441878882263925 | 0 | 3.112889888139514e-5 | 0.016410750703628525 | |
Czech Republic | Tsjechië | 0.03435435295921774 | 0.026191680362151484 | 0.008162672597066253 | 1.1137548315547124e-4 | 2.493278062811773e-4 | 0.0078019690694974215 | |
Denmark | Denemarken | 0.026361139279030256 | 0.013919593855795685 | 0.012441545423234574 | 5.218967541457303e-4 | 4.245805505706477e-4 | 0.011495068526242262 | |
Estonia | Estland | 0.05376745336568434 | 0.04815757511181799 | 0.005609878253866348 | 0 | -4.206117212672634e-5 | 0.005651939447634754 | |
Finland | Finland | 0.026965068275298064 | 0.011894628015050783 | 0.015070440260247285 | 7.432146171422945e-4 | 5.933064515828992e-4 | 0.0137339196933924 | |
France | Frankrijk | 0.1536952661409962 | 0.08149595588912459 | 0.07219931025187164 | 0.00808298525807954 | 0.021061359861385787 | 0.04305496903078258 | |
Germany | Duitsland | 0.16040134679655849 | 0.04867301124094495 | 0.11172833555561354 | 8.985934232796183e-4 | 0.005172771138946808 | 0.10565697578283019 | |
Greece | Griekenland | 0.3615910825853395 | 0.2947691458089319 | 0.06682193677640759 | 8.673295123887352e-4 | 0.001333239064880308 | 0.06462136718081903 | |
Hungary | Hongarije | 0.027387785710283812 | 0.016912083084059042 | 0.01047570262622477 | 6.340495884072204e-4 | 5.28586333666019e-4 | 0.0093130672819012085 | |
Iceland | IJsland | 0.16445669561411433 | 0.007400459443535558 | 0.15705623617057876 | 4.840509427130757e-4 | 0.0011712500735728995 | 0.15540093828079382 | |
Ireland | Ierland | 0.10000561783804358 | 0.006822340760740161 | 0.09318327707730342 | 0.01393625160848962 | 0.005511718250205535 | 0.0737353104250802 | |
Italy | Italië | 0.11899424903668598 | 0.10620931459087252 | 0.01278493444581348 | 2.0438722245982318e-4 | 0.001013412312610607 | 0.011567135307848976 | |
Latvia | Letland | 0.03649997970980231 | 0.030612879260791828 | 0.0058871004490104835 | 7.23411287207538e-5 | 0 | 0.005814759405634823 | |
Lithuania | Litouwen | 0.020230629020817244 | 0.0170038122334525 | 0.003226816787364742 | 9.375710485240537e-6 | 6.276528568653519e-5 | 0.0031546757669322833 | |
Macedonia | Noord-Macedonië | 0.05502011987084641 | 0.036675215768469764 | 0.01834490410237664 | 0 | 7.479712003861966e-5 | 0.01827010648483201 | |
Moldova | Moldavië | 0.04010546035825843 | 0.025960999031409394 | 0.014144461326849034 | 0 | 0 | 0.014144461096255292 | |
Netherlands | Nederland | 0.06028583941093653 | 0.01580378983804355 | 0.04448204957289298 | 0.001915358789197904 | 0.002909379345539314 | 0.039657310685168194 | |
Norway | Noorwegen | 0.035152324223367455 | 0.010524018998910022 | 0.02462830522445744 | 0.00184223880197029 | 0.0027562123571129213 | 0.020029853704322968 | |
Poland | Polen | 0.01497032261232359 | 0.011056714362747489 | 0.003913608249576102 | 1.4842200719273924e-4 | 1.1185317501748926e-4 | 0.0036533330926707326 | |
Portugal | Portugal | 0.21225323407439023 | 0.11551497829777681 | 0.09673825577661342 | 0.008168606787150487 | 0.044393630384691525 | 0.044176020205745195 | |
Romania | Roemenië | 0.013504400484876793 | 0.010232508328499942 | 0.0032718921563768496 | 8.591373911721291e-5 | -2.4233671643094794e-6 | 0.003188401784674569 | |
Serbia | Servië | 0.040417631188243236 | 0.03545897947058286 | 0.004958651717660374 | 0 | -2.0635440315706983e-4 | 0.005165005931564471 | |
Slovakia | Slowakije | 0.024311677542387108 | 0.01685464254304961 | 0.007457034999337501 | 0 | 0 | 0.007457034866428707 | |
Slovenia | Slovenië | 0.02793001092979509 | 0.011283992341841933 | 0.016646018587953157 | 0 | 0 | 0.016646019191897198 | |
Spain | Spanje | 0.11071964381879779 | 0.09451076275173796 | 0.016208881067059824 | 6.36343495173106e-4 | 0.001947757930710036 | 0.013624779811186177 | |
Sweden | Zweden | 0.058319220377755325 | 0.02632761772430725 | 0.03199160265344808 | 0.0059197196802119115 | 0.0010992833385367665 | 0.02497259919862181 | |
Ukraine | Oekraïne | 0.033499001800821326 | 0.026819578830878574 | 0.0066794229699427545 | 6.71972269050857e-5 | 0 | 0.006612225932388829 | |
UK | Verenigd Koninkrijk | 0.1626398322601674 | 0.05007731503263585 | 0.11256251722753154 | 0.02306405752975668 | 0.014017362404981474 | 0.0754810950360598 |
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
# ############################################################ # | |
# Barchart offshore wealth BE in Swiss/non-Swiss jurisdictions # | |
# ############################################################ # | |
library(here) | |
library(readr) | |
library(dplyr) | |
library(assertr) | |
library(ggplot2) | |
library(hrbrthemes) | |
library(tidyr) | |
library(gghighlight) | |
library(ggtext) | |
library(forcats) | |
d_offshore_gdp_eu <-read_csv( | |
file = 'alstadsaeter_2018_offshore_eu_gdp_swiss.csv', | |
col_types = cols( | |
country_name_en = col_character(), | |
country_name_nl = col_character(), | |
offshore_total_gpd_pct = col_double(), | |
offshore_swiss_gpd_pct = col_double(), | |
offshore_nonswiss_gpd_pct = col_double(), | |
offshore_nonswiss_caribbean_gpd_pct = col_double(), | |
offshore_nonswiss_asia_gpd_pct = col_double(), | |
offshore_nonswiss_eu_gpd_pct = col_double() )) %>% | |
verify(dim(.) == c(33, 8)) | |
# Get country order by %gdp offshore wealth, and order via factor() | |
country_order <- d_offshore_gdp_eu %>% | |
arrange(desc(offshore_total_gpd_pct)) %>% | |
pull(country_name_nl) | |
d_offshore_gdp_eu <- d_offshore_gdp_eu %>% | |
arrange(offshore_total_gpd_pct) %>% | |
mutate(country_name_nl_f = factor( | |
country_name_nl, | |
levels = rev(country_order))) | |
# Construct barchart | |
# ------------------ | |
p_offshore_gdp_eu_be <- d_offshore_gdp_eu %>% | |
select(country_name_nl_f, offshore_swiss_gpd_pct, | |
offshore_nonswiss_gpd_pct) %>% | |
mutate(country_name_nl_f = fct_recode( # Recode factor level for Belgium with markdown '**' to | |
country_name_nl_f, # bold the label using element_markdown(). | |
`**België**` = 'België')) %>% | |
pivot_longer( | |
cols = offshore_swiss_gpd_pct:offshore_nonswiss_gpd_pct, | |
names_to = 'offshore_location', | |
values_to = 'gdp_pct') %>% | |
ggplot(aes( | |
x = gdp_pct, | |
y = country_name_nl_f, | |
group = offshore_location, fill = offshore_location)) | |
p_offshore_gdp_eu_be <- p_offshore_gdp_eu_be + | |
geom_bar(stat = 'identity') + | |
gghighlight( | |
country_name_nl_f == '**België**', # highlight Belgium, with bolded label | |
unhighlighted_params = list( # Do not "unhighlight" the rest by greying out, | |
color = NULL, # but keep color (set to NULL) and | |
fill = NULL, # adjust alpha for non-highlighted countries | |
alpha = 0.3)) + # instead to make them less prominent. | |
scale_x_continuous( | |
labels = scales::percent_format(accuracy = 1), | |
breaks = c(0, .10, .174, .30)) + # explicitly indicate 17,3% for Belgium | |
scale_fill_brewer(palette = 'Set1', direction = -1) | |
p_offshore_gdp_eu_be <- p_offshore_gdp_eu_be + | |
theme_ipsum_rc() + | |
theme( | |
legend.position = 'none', | |
panel.grid.major.y = element_blank(), # Remove grid lines | |
panel.grid.minor.x = element_blank(), | |
axis.text.y = element_markdown( # Move y-axis tick labels (country names) | |
margin=margin(r=-15)), # closer to start of the bars, and adjust | |
plot.title = element_markdown( # the (sub)title accordingly (+15pt). | |
padding = unit(c(0, 0, 0, 15), "pt")), | |
plot.subtitle = element_markdown( | |
family = 'Roboto Condensed', # Switch to Roboto Condensed, as you can't bold | |
padding = unit(c(0, 0, 0, 15), "pt"))) # the default Roboto Light | |
p_offshore_gdp_eu_be <- p_offshore_gdp_eu_be + | |
labs( | |
title = 'Belgische rijken zijn mee EU-koploper in het<br>gebruik van (Zwitserse) belastingsparadijzen', | |
subtitle = 'Vermogen per Europees land dat zich <strong style="color:#E41A1C">in Zwitserland</strong> en <strong style="color:#377EB8">in niet-Zwitserse</strong><br>belastingsparadijzen bevindt, als percentage van het BBP.', | |
caption = 'Bron: Alstadsæter, Johannesen & Zucman (2018) • Visualisatie: @hermansm • Denktank Minerva.', | |
y = NULL, x = NULL ) | |
# annotate graph with text box with styled text using ggtext, and an arrow from | |
# the text box to the observation row for Belgium. | |
p_offshore_gdp_eu_be <- p_offshore_gdp_eu_be + | |
annotate("curve", x = 0.23, y = 17, xend = 0.175, yend = 31, | |
colour = "grey80", size=.4, alpha=1, | |
arrow=arrow(length = unit(8, 'pt'), type = 'closed')) + | |
annotate( | |
geom='richtext', fill = 'white', label.color = 'grey80', x=0.22, y=17, | |
family = 'Roboto Condensed', | |
label='Een vermogen ter waarde van **17,4%** van het<br>Belgisch BBP bevindt zich in belastingsparadijzen,<br> | |
waarvan <strong style="color:#E41A1C">10,4% in Zwitserland</strong> en<br> | |
<strong style="color:#377EB8">7% in overige belastingsparadijzen</strong>.') | |
ggsave( | |
'barchart_offshore_gdp_eu_be_nl.png', | |
p_offshore_gdp_eu_be, width = 8, height = 8, | |
bg = 'white') # set background to be white, otherwise theme defaults will make it transparent here. | |
Author
mhermans
commented
Feb 26, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment