networkD3 icon indicating copy to clipboard operation
networkD3 copied to clipboard

as_treenetdf.data.frame should handle implicit root nodes better

Open cjyetman opened this issue 7 years ago • 0 comments

Ideally, data passed to as_treenetdf.data.frame should include information about every node, including the root node, such as...

library(networkD3)
data <- read.csv(header = T, text = "
nodeId,parentId
root,
L2-1,root
L2-2,root
L3-1,L2-1
L3-2,L2-1
L3-3,L2-2
L3-4,L2-2
")
as_treenetdf(data)

In some cases, a user may expect that the root node will be inferred from the data. This could be expected with numerous possibilities...

  1. root node is listed as the parentId of multiple child nodes, but not explicitly listed itself as a nodeId
library(networkD3)
data <- read.csv(header = T, text = "
nodeId,parentId
L2-1,root
L2-2,root
L3-1,L2-1
L3-2,L2-1
L3-3,L2-2
L3-4,L2-2
")
as_treenetdf(data)
  1. multiple nodes do not have a parentID node explicitly named, and therefore should be considered the children of a root node
library(networkD3)
data <- read.csv(header = T, text = "
nodeId,parentId
L2-1,
L2-2,
L3-1,L2-1
L3-2,L2-1
L3-3,L2-2
L3-4,L2-2
")
as_treenetdf(data)

or

library(networkD3)
data <- read.csv(header = T, text = "
nodeId,parentId
L2-1,NA
L2-2,NA
L3-1,L2-1
L3-2,L2-1
L3-3,L2-2
L3-4,L2-2
")
as_treenetdf(data)

It could be that the data represent two separate branches and do not share a root node, but since the plotting function does not support plotting two separate branches, maybe it's safe to assume there's a shared root node?

I noticed this problem while investigating the example given in #224

cjyetman avatar Dec 01 '17 12:12 cjyetman