Show the code
war_support_tracker <- readxl::read_xlsx(here::here("./data/UkraineTracker_v2_02052022.xlsx"), sheet="Aggregate Aid", range = "A1:S33")This post inspired me to look at how distance from the war in Ukraine correlates with amount of money sent to Russia.
Ukraine War Tracker data from the IFW-Kiel Institute for the World Economy (Retrieved 2022-05-10)
war_support_tracker <- readxl::read_xlsx(here::here("./data/UkraineTracker_v2_02052022.xlsx"), sheet="Aggregate Aid", range = "A1:S33")You can add options to executable code like this
Warning: Geocoding "EU (Commission an..." failed with error:
# A tibble: 6 x 3
Country `Direct Military Aid` `GDP (EUR)`
<chr> <dbl> <dbl>
1 Estonia 0.22 28153109213.
2 Latvia 0.22 30961072839.
3 Poland 1.47 548015394507.
4 Luxembourg 0.00303 67376807201.
5 Slovakia 0.195 96603802700.
6 Lithuania 0.039 51939891614.
war_support_tracker %>%
filter(!str_detect(Country,"Commission")) %>%
ggplot(aes(`Total aid (bilateral + EU) in % of GDP`)) +
geom_histogram(fill = ukraine_palette$ukraine_blue) +
labs(title = "Total Aid in % GDP of Selected Countries") +
ukraine_plot_theme()`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
war_support_tracker %>%
filter(!str_detect(Country,"Commission")) %>%
ggplot(
aes(fct_reorder(Country, `Total aid (bilateral + EU) in % of GDP`),
`Total aid (bilateral + EU) in % of GDP`)
) +
geom_col(fill = ukraine_palette$ukraine_blue) +
labs(title = "Total Aid in % GDP of Selected Countries", x = "Country") +
ukraine_plot_theme() +
coord_flip()moscow_geolocation = ggmap::geocode("Moscow")
google_map_geo_to_vector <- function(geo){ c(geo$lon, geo$lat) }
war_support_tracker <-
war_support_tracker %>%
mutate(
country_geolocation = purrr::map(
country_geolocation,
google_map_geo_to_vector
),
moscow_distance_km = purrr::map_dbl(
country_geolocation,
geosphere::distVincentyEllipsoid,
p2=google_map_geo_to_vector(moscow_geolocation)
) / 1000
)war_support_tracker %>%
ggplot(
aes(
moscow_distance_km,
`Total aid (bilateral + EU) in % of GDP`,
size = `GDP (EUR)`
)
) +
geom_point(colour = ukraine_palette$ukraine_blue, alpha=0.7) +
ukraine_plot_theme() +
scale_size(range = c(0.1, 15),
breaks = c(1e12, 5e12, 10e12, 15e12),
labels = c("1", "5", "10", "15"),
name = "GDP (Trillion EUR)") +
labs(title = "Country Distance to Moscow vs GDP Aid to Ukraine",
x = "Distance from Country Centre to Moscow")Warning: Removed 1 rows containing missing values (geom_point).
war_support_tracker %>%
ggplot(
aes(
moscow_distance_km,
`Total aid (bilateral + EU) in % of GDP`,
size = `GDP (EUR)`
)
) +
geom_point(colour = ukraine_palette$ukraine_blue, alpha=0.7) +
ukraine_plot_theme() +
scale_size(range = c(0.1, 15),
breaks = c(1e12, 5e12, 10e12, 15e12),
labels = c("1", "5", "10", "15"),
name = "GDP (Trillion EUR)") +
labs(title = "Country Distance to Moscow vs GDP Aid to Ukraine",
x = "Distance from Country Centre to Moscow")aid_vs_distance_eu_lm <-
war_support_tracker %>%
filter(EU == 1) %>%
select(
moscow_distance_km, `Total aid (bilateral + EU) in % of GDP`, `GDP (EUR)`
) %>%
mutate(across(c(moscow_distance_km), .fns=log10)) %>%
lm(formula = `Total aid (bilateral + EU) in % of GDP` ~ moscow_distance_km,
data=.)
aid_vs_distance_eu_lm_summary = summary(aid_vs_distance_eu_lm)
aid_vs_distance_eu_lm_summary
Call:
lm(formula = `Total aid (bilateral + EU) in % of GDP` ~ moscow_distance_km,
data = .)
Residuals:
Min 1Q Median 3Q Max
-0.29911 -0.10970 -0.03176 0.03689 0.42300
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.4922 0.6160 4.046 0.000440 ***
moscow_distance_km -0.7159 0.1891 -3.785 0.000859 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1732 on 25 degrees of freedom
Multiple R-squared: 0.3643, Adjusted R-squared: 0.3388
F-statistic: 14.32 on 1 and 25 DF, p-value: 0.0008594
war_support_tracker %>%
filter(EU == 1) %>%
select(
Country,
moscow_distance_km,
`Total aid (bilateral + EU) in % of GDP`,
`GDP (EUR)`
) %>%
mutate(
across(
c(
moscow_distance_km,
# `Total aid (bilateral + EU) in % of GDP`
),
.fns=log10)
) %>%
mutate(`GDP (EUR) ` = `GDP (EUR)`) %>%
ggplot(
aes(
moscow_distance_km,
`Total aid (bilateral + EU) in % of GDP`,
size = `GDP (EUR)`
)
) +
geom_point(aes(
moscow_distance_km,
`Total aid (bilateral + EU) in % of GDP`,
size = `GDP (EUR) `
),
colour = ukraine_palette$ukraine_blue, alpha=0.6) +
ukraine_plot_theme() +
scale_size(range = c(0.5, 15),
breaks = c(0.1e12, 1e12, 3e12),
labels = c("0.1", "1", "3"),
name = "GDP (Trillion EUR)") +
labs(title = "Log of EU Country Distance to Moscow vs GDP % Aid to Ukraine",
x = "Log10 Distance from Country to Moscow",
y = "Total Aid as % of GDP") +
geom_smooth(method = "lm",
show.legend = FALSE,
se = FALSE,
formula = y ~ x,
colour = ukraine_palette$ukraine_yellow_darkened) +
annotate("text",
x=Inf,
y = Inf,
label = paste0(
"R² = ", round(aid_vs_distance_eu_lm_summary$r.squared, 2)
),
vjust=1.2,
hjust=1.1,
colour = ukraine_palette$text_colour,
size=6) +
geom_text(mapping = aes(label = Country),
check_overlap = TRUE,
size = 5,
colour = ukraine_palette$text_colour,
hjust = -0.2) +
xlim(2.9, 3.7) +
ylim(0, 1)war_support_tracker %>%
select(
moscow_distance_km, `Total aid (bilateral + EU) in % of GDP`, `GDP (EUR)`
) %>%
# mutate(across(.fns=log10)) %>%
cor() %>%
corrplot::corrplot(method="number")