# Install necessary packages (if not installed):
# install.packages("collapsibleTree")
# install.packages("readxl")
# install.packages("dplyr")
# install.packages("colorspace")
# Load libraries
library(collapsibleTree)
library(readxl)
library(dplyr)
library(colorspace)
Learning Collection
Getting Started with Collapsible Trees using R: A Simple Tutorial
In this tutorial, we will explore how to generate collapsible trees with the collapsibleTree package in R. Let’s begin by installing and loading the required packages if you haven’t already. You may need to modify the installation paths based on your system configuration.
Now let’s load our dataset containing geographical information. In this example, we use an Excel file named ‘Geography Table_Data.World.xlsx’ downloaded from (https://data.world/glx/geography-table). Adjust the path accordingly for your local files.
# Read data from Excel file
<- read_xlsx("C:/Users/Zobaer Ahmed/Documents/Zobaer_github_page/portfolio/data/Geography Table_Data.World.xlsx")
Geography
# Display summary of loaded data (if needed delete the "#" sign)
# summary(Geography)
Next, we will display a collapsible tree representing the hierarchical structure of continents, types, and countries using the collapsibleTree() function. Click any node and see the magic
.
To further customize the tree, we can calculate the number of countries per continent and type, then add these counts as attributes for each node. This allows us to view the count when expanding nodes.
Lastly, let’s demonstrate creating a collapsible tree for organizational structures using a sample dataset. Replace the last two code blocks below with the following examples.
Complex Collapsible Trees Example
I have generated a complex collaborative tree utilizing my proprietary datasets, which unfortunately cannot be shared publicly. However, I would like to provide you with a snapshot of the expanded tree above.
If you wish to recreate similar results using your own datasets, follow the steps outlined in the earlier parts of this tutorial. Remember, the process involves importing data into R, cleaning it up, and finally rendering the tree using the `collapsibleTree()` function from the `collapsibleTree` package. Good luck, and feel free to reach out if you encounter any issues during implementation!
Enjoyed the tutorial? Consider fueling my efforts with a coffee!
References: This tutorial is based on the documentation provided by Adeel Khan on his https://adeelk93.github.io/collapsibleTree/