as_treenetdf | R Documentation |
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:
it's an easy to use and understand R-like format
a hierarchical network can be succinctly defined by a list of each unique node and its parent node
since each row defines a unique node, additional columns can be added to add node-specific properties
in a hierarchical network, every link/edge can be uniquely identified by the node which it leads to, therefore each link/edge can also be specifically addressed by adding columns for formatting of the incoming link
as_treenetdf
can convert from any of the following data types:
leafpathdf
(table)–parent|parent|node
–data.frame
hierarchical nested list (JSON)
hclust
data.tree
Node
igraph
ape phylo
as_treenetdf(data = NULL, ...)
data |
a tree network description in one of numerous forms (see details). |
... |
other arguments that will be passed on to as_treenetdf |
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'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.