Open areeves87 opened 6 years ago
At the moment, no, there is no exported function to do specifically that task. The simpleNetwork
function does that internally before passing on to forceNetwork
with...
# create nodes data
node_names <- factor(sort(unique(c(as.character(sources), as.character(targets)))))
nodes <- data.frame(name = node_names, group = 1, size = 8)
# create links data
links <- data.frame(source = match(sources, node_names) - 1,
target = match(targets, node_names) - 1,
value = 1)
I’ve been working on a major overhaul of networkD3
that has an exported data conversion function that would handle that situation, among many other data types, automatically, but I haven’t committed any of it yet. It’s likely that igraph
and/or tidygraph
have something like that too.
Is there a native munging function for getting a 2-column (source->target) data.frame into a link list and node list format?
The 2-column dataframe has the following format
The link list would be:
and the node list would be
I can get the data into this format but I want to know if there are standard methods for doing so?