Do you want to share your content on R-bloggers? Click here if you have a blog, or here If you don’t.
If this message is useful for you, I kindly request a minimum donation Buy a coffee for me. It will be used to continue my open source efforts. The complete explanation is here: A personal message from an Open Source employee.
You can send me questions for the blog using This form And subscribe to receive an e -mail when there is a new message.
I have added 2023 trade data and GDP information in addition to new suddenly that I think are easier to understand than the previous one: https://shiny.tradestatistics.io.
In 2017 I had to download tradedatasets and realized that gaining access to UN Comtrade in Latin America was particularly difficult because local universities there are no institutional access to.
I called this to colleagues from PUC Chile and decided to e -mail the United Nations to ask permission to get the data with an access of 48 hours so that I could download it and hang the data sets again. They agreed that I could share a derivative data set with cleaning/transforming steps, but the unprocessed data could not hang again, and I did. I cleaned the data set as much as possible and I used mirrored flows for consistency (ie on importer -based figures are more reliable).
Nine years later this project continues and it is worth receiving e -mails from Latin -America and other development regions that use this. For the record, I never formally studied it or IT. I learned SQL, Nginx and Rest APIs by reading and experimenting Stack Overflow to make this service.
You can download the data from the website in CSV/Excel -Layout or the R -package from Cran Install with:
install.packages("tradestatistics")The package documentation includes several examples (https://docs.ropensci.org/tradestatistics/articles/basic-usage.html). Here is a simple example:
library(tradestatistics)
library(dplyr)
library(tidyr)
library(ggplot2)
# Bilateral aggregate trade between the United Kingdom, France and Germany 2020-2023
yr <- ots_create_tidy_data(
years = 2020:2023,
reporters = "GBR",
partners = c("FRA", "DEU"),
table = "yrp"
)
yr2 <- yr |>
pivot_longer(
cols = c("trade_value_usd_exp", "trade_value_usd_imp"),
names_to = "trade_flow",
values_to = "trade_value_usd"
) |>
mutate(
trade_flow = recode(trade_flow,
"trade_value_usd_exp" = "Exports",
"trade_value_usd_imp" = "Imports"
)
)
ggplot(yr2, aes(x = year, y = trade_value_usd / 1e9, fill = trade_flow)) +
geom_col(position = "dodge") +
facet_wrap(~partner_name, ncol = 2) +
labs(
title = "UK bilateral trade with France and Germany",
subtitle = "2020-2023, in billion USD",
x = "Year",
y = "Trade value (billion USD)",
fill = "Trade flow"
) +
theme_minimal(base_size = 13) +
theme(legend.position = "top") +
tintin::scale_fill_tintin_d()
Related
#Open #Trade #Statistics #V6.0 #publicly #RBloggers

