Skip to content

24-7 Today

Menu
  • Home
  • Ads Guide
  • Blogging
  • Sec Tips
  • SEO Strategies
Menu

Open Trade Statistics v6.0 is publicly available!

Posted on September 23, 2025 by 24-7

[This article was first published on pacha.dev/blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

If this post is useful to you I kindly ask a minimal donation on Buy Me a Coffee. It shall be used to continue my Open Source efforts. The full explanation is here: A Personal Message from an Open Source Contributor.

You can send me questions for the blog using this form and subscribe to receive an email when there is a new post.

I added 2023 trade data and GDP information besides new plots that I think are more easy to understand than the previous ones: https://shiny.tradestatistics.io.

Updated dashboard

Back in 2017, I needed to download tradedatasets and realised that obtaining access to UN Comtrade in Latin America was particularly hard because local universities lacked institutional access to those.

I mentioned this to colleagues at PUC Chile and decided to email the United Nations to ask for permission to get the data with a 48 hrs access so that I could download it and reshare the datasets. They agreed that I could share a derived dataset with cleaning/transforming steps but not reshare the raw data, and I did that. I cleaned the dataset as much as I could and used mirrored flows for consistency (i.e., importer-based figures are more reliable).

Nine years later, this project continues and it is rewarding to get emails from Latin America and other developing regions that use this. For the record, I never formally studied IT or Computer Science. I learned SQL, Nginx, and REST APIs by reading Stack Overflow and experimenting to create this service.

You can download the data from the website in CSV/Excel format or install the R package from CRAN with:

install.packages("tradestatistics")

The package documentation covers multiple 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

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

©2025 24-7 Today | Design: WordPress | Design: Facts