as_treenetdf {networkD3}R Documentation

Convert one of numerous data types to treeNetwork's 'native' treenetdf form

Description

The treeNetwork function uses a 'native' data format that consists of a data frame with minimally 2 vectors/columns, one named 'nodeId' and one named 'parentId'. Other columns in the data frame are also passed on to the JavaScript code and attached to the elements in the D3 visualization so that they can potentially be accessed by other JavaScript functions. This is an advantageous format because:

as_treenetdf can convert from any of the following data types:

Usage

as_treenetdf(data = NULL, ...)

Arguments

data

a tree network description in one of numerous forms (see details).

...

other arguments that will be passed on to as_treenetdf

Examples

links <- read.csv(header = TRUE, stringsAsFactors = FALSE, text = '
                   source,target,name
                   1,,one
                   2,1,two
                   3,1,three
                   4,1,four
                   5,2,five
                   6,2,six
                   7,2,seven
                   8,6,eight')
                   
 # Convert data
 as_treenetdf(links, cols = c(nodeId = 'source', parentId = 'target'))
 
 # Graph (calls as_treenetdf internally)
 treeNetwork(links, cols = c(nodeId = 'source', parentId = 'target'))


[Package networkD3 version 0.4.1 Index]