Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating list for trees with an edgelist #224

Open
chendaniely opened this issue Nov 28, 2017 · 1 comment
Open

Creating list for trees with an edgelist #224

chendaniely opened this issue Nov 28, 2017 · 1 comment

Comments

@chendaniely
Copy link

chendaniely commented Nov 28, 2017

Here's a snippet of code when you have an edgelist and want to use it to create one of the tree diagrams (e.g., radialNetwork)

library(data.tree)
library(networkD3)

pokemon <- structure(list(name = structure(c(5L, 4L, 6L, 1L, 7L, 3L, 2L), .Label = c("Eevee", 
"Flareon", "Jolteon", "Pichu", "Pikachu", "Raichu", "Vaporeon"
), class = "factor"), meta.contruct = structure(c(3L, 1L, 4L, 
1L, 2L, 2L, 2L), .Label = c("", "Eevee", "Pichu", "Pikachu"), class = "factor")), .Names = c("name", 
"meta.contruct"), class = "data.frame", row.names = c(NA, -7L
))

tree <- FromDataFrameNetwork(pokemon[, 1:2])
pokelist <- ToListExplicit(tree, unname = TRUE)

radialNetwork(pokelist)

would this be good to put in the docs for radialNetwork?

@cjyetman
Copy link
Collaborator

In the current dev version of networkD3, treeNetwork supersedes radialNetwork and the other tree network plotting functions. treeNetwork should handle an 'edgelist' as in your example, though your example does expose a problem when a root node is not specified in the data. Modifying your example somewhat, the following does work...

pokemon <- read.csv(header = T, text = "
name,meta.contruct
root,
Pikachu,Pichu
Pichu,root
Raichu,Pikachu
Eevee,root
Vaporeon,Eevee
Jolteon,Eevee
Flareon,Eevee
")

treeNetwork(pokemon, direction = "radial", 
            cols = c(nodeId = "name", parentId = "meta.contruct"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants