Created
April 3, 2025 00:06
-
-
Save bbolker/9e0b94d43de7cd9ebfbc357f40170b2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
download.file("https://www.census.gov/foreign-trade/balance/country.xlsx", dest = "balance.xlsx") | |
library(readxl) | |
library(dplyr) | |
library(ggplot2); theme_set(theme_bw()) | |
library(ggrepel) | |
bdat <- read_excel("balance.xlsx") |> | |
filter(year == 2024) |> | |
select(countrycode=CTY_CODE, country=CTYNAME,imports=IYR,exports=EYR) | |
download.file("https://gist.githubusercontent.com/jmcastagnetto/eb3c860a6877b5b97adb18f8ececbf5f/raw/377058a18d8c731e0e7a1beae8cdef0b90d44096/tariffs.csv", dest = "tariffs.csv") | |
tdat <- read.csv("tariffs.csv") | |
comb <- right_join(bdat, tdat, by = "country") |> arrange(desc(imports)) |> | |
mutate(t2 = 1-exports/imports) | |
ggplot(comb, | |
aes(t2*100, tariffs_charged)) + | |
geom_function(fun = function(x) pmax(x, 10), colour = "red") + | |
geom_point(size =3) + | |
expand_limits(y=0) + | |
geom_text_repel(data = filter(comb, t2 > 0.3), | |
aes(label = country)) + | |
labs(y = "tariff charged (%)", x = "(1-exports/imports)*100") + | |
geom_vline(xintercept = 10, lty = 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment