d3tree: Create an Interactive Treemap (Version 1)

Description Usage Arguments Examples

Description

d3tree is the primary function for creating interactive d3.js treemaps from various data types in R. Easily use treemap plots customized with treemap, or supply a list for a more typical d3.js experience, or blend the two.

Usage

1
2
d3tree(data = NULL, rootname = NULL, id = "id", celltext = "name",
  valueField = "size", width = NULL, height = NULL)

Arguments

data

the data to be plotted as either the result of treemap or a list or JSON as character or file in the form of a d3.js hierarchy.

rootname

character for the name of the root if data is a treemap object.

id

character of the name or id. The default is "id". Often d3.js hierarchies will use "name" instead of "id". We will use id as the default to allow nodes with non-unique names.

celltext

character of the field that contains the title for each cell. The default is "name".

valueField

character of the name of the field containing the value on which you would like your treemap based. The default is "size".

width,height

a valid CSS size for the width and height of the container. Percentage values work also by supplying as character such as width = "100%"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
## Not run: 
#####  designed to work seamlessly with treemap
library(treemap)
library(d3treeR)

# example 1 from ?treemap
data(GNI2010)
d3tree(
   treemap(
     GNI2010
     ,index=c("continent", "iso3")
     ,vSize="population"
     ,vColor="GNI"
     ,type="value"
   )
   , rootname = "World"
)

## End(Not run)

# last example from ?treemap
data(business)
# Brewer's Red-White-Grey palette reversed with predefined range
business$employees.growth <- business$employees - business$employees.prev
d3tree(
  treemap(business,
       index=c("NACE1", "NACE2"),
       vSize="employees",
       vColor="employees.growth",
       type="value",
       palette="-RdGy",
       range=c(-30000,30000))
  , rootname="Fictitious Business Data"
)
####

#### also works with d3.js json
library(d3tree)
d3tree(
  "http://bl.ocks.org/mbostock/raw/4063269/flare.json"
  ,id = "name"
)
####

d3treeR/d3treeR documentation built on May 27, 2019, 3:30 p.m.