Home » Uncategorized

Build interactive Tree like D3.js in R

Last year while working on some natural language projects, I happen to stumble on the D3 charts. I was impressed by the quality of the charts and the amount of information one can share using those charts. In particular, I picked a collapsible dendrogram as I wanted to showcase how different topics are related hierarchically. 

Since then, I used and built many interactive charts using some of the most famous packages like plotly and gganimate ( it is an extension of ggplot) in R.

Why interactive plots?

An interactive chart enables the presenter to share complex ideas in an engaging way as it allows users to perform actions like choosing a variable, zoom-in, zoom-out, hover to get tooltip, take a snapshot, and more. 

The Challenge

The only challenge with building D3 like plots is data preparation. It can be a little too much for a newbie to build something in a reasonable time frame. But, don’t worry, as part of my job I happen to do a decent about of research to collected a list of packages in R we can use to build not just the collapsible tree but something more complicated like network graphs in just a matter of minutes if not hours. 

R Code for building Collapsible tree

library(“collapsibleTree”)

geo <- read.csv(“M:/DSB/datasets/Machine-Learning/Geography.csv”)

dendo <- collapsibleTree( geo, hierarchy = c(“region”, “sub_region”), width = 700, zoomable = TRUE )

dendo

I hope you find this code of interest. I am just starting to blog and find my way through HTML tags and all. But if you are interested in learning how to build some of the basic to advance interactive charts in R, feel free to read through 7 Useful Interactive Charts in R (with sample code).

If you need some help with career guidance, code, or algorithm, please free to drop a note here. I will be more than happy to assist and answer your queries. This is a free service, so please don’t restrict yourself from dropping a note. If you are wondering why free? Then all I can tell you is that it gives me immense satisfaction and happiness.