Site icon R-bloggers

An update to Open Trade Statistics to showcase Tabler and D3po

[This article was first published on https://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.
< !DOCTYPE html> < charset="utf-8"> < http-equiv="X-UA-Compatible" content="IE=edge"> < name="viewport" content="width=device-width, initial-scale=1.0"> pacha.dev/blog < !-- MathJax Configuration --> < !-- Smart header: libraries detected based on content --> < !-- File: /tmp/tmp.EeOBMTrWn7/index.html -->
  • < !-- DEBUG: Found sourceCode --> < !-- DEBUG: Found htmlwidgets --> < !-- DEBUG: Found D3 --> < !-- DEBUG: Found d3po --> < !-- DEBUG: Found class with d3po --> < !-- Load custom CSS after any library CSS to ensure proper precedence -->
  • < header class="site-top">

    Mauricio “Pachá” Vargas Sepúlveda

    Blog with notes about R, Shiny, SQL, Python, Linux and C++. This blog is listed on R-Bloggers.

    HOME 🏠
    < !-- categories are printed below this--> < nav class="sidebar-nav">

    Categories

    < header id="title-block-header" class="quarto-title-block default">

    An update to Open Trade Statistics to showcase Tabler and D3po

    Showcasing D3po groups and subgroups for data visualization
    Author

    Mauricio “Pachá” Vargas S.

    Published

    October 28, 2025

    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.

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

    I updated Open Trade Statistics to showcase the new Tabler for R and D3po packages.

    Recently, I updated Open Trade Statistics to include 2023 data derived from UN Comtrade.

    While the data update was straightforward, I took the opportunity to revamp the dashboard using Tabler for R to enhance the user interface and D3po for interactive visualizations. One of the things I worked on, because I maintain both packages, was to ensure that building treemaps with D3po was as simple as possible.

    Here is a screenshot of the updated dashboard:

    Country profile: United Kingdom

    Product profile: Machinery and mechanical appliances

    While Highcharts requires a sophisticated code to render nested treemaps as an end user, D3po makes it easy with the po_treemap() function and moves the complexity to the package internals.

    Here is an example of how to create a nested treemap with D3po (clicable):

    library(d3po)
    Loading required package: htmlwidgets
    Loading required package: magrittr
    set.seed(123)
    
    d <- data.frame(
      category = c(rep("Apples", 5), rep("Bananas", 4)),
      subcategory = c(
        "Fuji", "Gala", "Honeycrisp", "Granny Smith", "Other",
        "Cavendish", "Lady Finger", "Red Banana", "Other"
      ),
      stock = rpois(9, 100),
      color = c(
        "#e44b5e", "#f26863", "#f98a5c", "#fbb07b", "#f9c1a2",
        "#feffc6", "#edffb9", "#e1ffaa", "#d5fdb8"
      )
    )
    
    d3po(d, width = 800, height = 600) %>%
        po_treemap(
            daes(size = stock, group = category, subgroup = subcategory, color = color, tiling = "squarify")
        )

    Here are the downloaded SVG images from the treemap above (e.g., for R-Bloggers):

    Fruits

    Apples

    Bananas

    I hope it’s useful!

    < footer>

    Loading…

  • < !-- Load shared sidebar -->
    To leave a comment for the author, please follow the link and comment on their blog: https://pacha.dev/blog.

    R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
    Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
    Exit mobile version