Week 29 | d3treeR v2

htmlwidgets News This Week

A gallery is up thanks to Ryan Hafen, but not “official”. As always, for all the newest and updated htmlwidgets, just do this Github search.

This Week’s Widget - d3treeR Again

d3treeR was released last week in the post Week 28 | d3treeR. We’ll do d3treeR again but we’ll make a version 2 d3tree2 using the versions from Mike Bostock’s Zoomable Treemaps and Zan Armstrong’s fork Zoomable Treemaps with Color.

This d3tree2 version should work much better when there are multiple levels of nesting or if you want a small in size d3tree. All it takes is one, so thanks so much for @ignacio82 for the motivation.

Quick Installation

d3treeR is not yet on CRAN and won’t be unless someone asks, so for now please install with devtools::install_github. If you installed last week, you’ll need to do this again.

# we'll need the newest data.tree
devtools::install_github("gluc/data.tree")
devtools::install_github("timelyportfolio/d3treeR")

Examples

Let’s look at the differences between d3tree and d3tree2 in the examples below. We’ll use the same examples as last week.

treemap as data

As stated in the introduction, d3treeR is built to work seamlessly with treemaps from the R treemap package.

# devtools::install_github("timelyportfolio/d3treeR")
library(treemap)
library(d3treeR)

# first example from ?treemap

data(GNI2010)

tm <-  treemap(
   GNI2010,
   index=c("continent", "iso3"),
   vSize="population",
   vColor="GNI",
   type="value"
 )


d3tree( tm,rootname = "World" )

d3tree2( tm,rootname = "World" )

# devtools::install_github("timelyportfolio/d3treeR")
library(treemap)
library(d3treeR)

# last example from ?treemap

data(business)
business$employees.growth <- business$employees - business$employees.prev

tm <- # Brewer's Red-White-Grey palette reversed with predefined range
  treemap(business,
          index=c("NACE1", "NACE2"),
          vSize="employees",
          vColor="employees.growth",
          type="value",
          palette="-RdGy",
          range=c(-30000,30000))

d3tree( tm, rootname = "World" )

d3tree2( tm, rootname = "World" )