Create treemaps with GNI2014 datasets (feat. treemap library)

When visualizing data, have you ever found it difficult to grasp a huge amount of information at a glance, especially when dealing with country-specific economic data? To solve this problem, why not try creating a treemap?

In this post, we'll take a look at R's treemap library to visualize the GNI2014 dataset. We'll walk you through the process of creating a treemap so you can easily understand the data visually, and you'll learn how to compare the GNI of each country by region. Make sure to read all the way through so you don't miss any important information!

Installing and loading libraries

To visualize a treemap, first use the treemap Install and load the library.

Install the # Treemap Library
install.packages("treemap")

Loading the # Treemap Library
library(treemap)

Preparing the GNI2014 dataset

The GNI2014 dataset is a built-in dataset in the treemap library that contains gross national income (GNI) and regional information for each country. The dataset contains the following variables

  • Country: Country name
  • Region: region name
  • Population: Population count
  • GNI: Gross National Income (GNI)
  • GNI_perCapitaGross National Income per capita

We'll use this dataset to generate a treemap.

Load the # GNI2014 dataset
data(GNI2014)

Verify # data
head(GNI2014)

Create a treemap

Now let's create a treemap using the GNI2014 dataset, visualizing the GNI of each country and grouping them by region.

Create a # Treemap
treemap(GNI2014,
index = c("continent", "country"),
vSize = "GNI",
vColor = "GNI",
type = "value",
title = "GNI2014 Dataset Treemap")

In the code above, the index parameter defines the hierarchy, vSizesets the size of each tile, vColorspecifies the color of each tile. typemeans color mapping by value. titlespecifies the title of the treemap.

Describe the output of creating a treemap

트리맵 만들기

When you run the source code, you'll end up with the same 'Treemap showing Gross National Income (GNI) by country for 2014' appears, with the following key characteristics

  1. Size: The size of the squares representing each country is GNI size of the countryof the system. The larger the square, the higher the GNI.
  2. ColorA color spectrum that changes from dark green to light green to beige indicates the GNI level. Darker green colors have higher GNI, lighter colors have lower GNI.
  3. Regionalization: Countries are Group by continent or region. For example, Europe, Asia, North America, etc. are clearly demarcated.
  4. ScaleThe colored bar at the bottom shows the range of GNI values, from 0 to over 1e+05 (100,000).

This visualization allows you to compare the size and relative economic strength of each country's economy at a glance, as well as understand the economic situation across continents. For example, you can see that countries in Europe and North America are generally dark green in color, indicating a high GNI, while countries in Africa and South America are relatively light in color, indicating a low GNI.

Additional explanation

The reason Bermuda and Norway are colored dark green is because they have very high GNI per capita, which we'll talk about in a bit more detail.

  1. Bermuda
    • Bermuda is a British Overseas Territory, a small island nation with a population of about 60,000 people.
    • Its main industries are international finance and tourism, and it is particularly well known as a tax haven.
    • It has a highly developed financial services industry and a high per capita income.
    • It has a very high GNI per capita due to its small population and focus on high-value industries.
  2. Norway
    • Norway is a developed country in Northern Europe with an abundance of natural resources.
    • In particular, the oil and natural gas resources of the North Sea contribute significantly to the country's economy.
    • Economic prosperity has been achieved through efficient resource management with a high level of social welfare.
    • It has a relatively small population of about 5.4 million people and a very high GNI per capita due to high-value industries such as the oil industry.

The fact that these two countries are colored dark green doesn't simply mean that their total GNI is large, but that they have a very high GNI per capita, or GNI per capita, relative to their population. This is a reflection of a country's economic prosperity and the high standard of living of its people.

It's also important to note, however, that this high GNI per capita doesn't necessarily mean equal wealth for all citizens, and that each country's particular economic structure and how resources are distributed must be taken into account.

Organize

Treemaps are a powerful tool for visually representing the hierarchical structure of your data. treemap library allows you to effectively visualize the GNI2014 dataset. This allows you to intuitively compare the GNI of different countries and regions.

Use the full source code below to create a treemap using your own data and get a taste of what visualization in R can be like.

Full source code

Install the # Treemap Library
install.packages("treemap")

Load the # treemap library
library(treemap)

Load the # GNI2014 dataset
data(GNI2014)

View # data
head(GNI2014)

Generate a # treemap
treemap(GNI2014,
        index = c("continent", "country"),
        vSize = "GNI",
        vColor = "GNI",
        type = "value",
        title = "GNI2014 dataset treemap")

Take a step forward

But the generated graph looks a bit dated. Wouldn't it be possible to draw a more trendy treemap like the one below? How can we make the graph more visually appealing? If you're curious Herefor more information.

더 멋진 트리맵 만들기

Additional resources

For additional information about the treemap library, please use the links below.

Similar Posts