Is it possible to plot multiple networks into 1 graph, by using forceNetwork for networkD3?
A sample (from the post Adjust background picture and title for plot from networkD3's forceNetwork) uses 1 set of nodes + edges (ie. subNodes & subLinkList). In a case when there are 4 sets of nodes + edges, and I want to put them all into 1 graph. How is it possible?
Thank you.
graph of 1 set of nodes + edges as below:
library(networkD3)
library(htmlwidgets)
subNodes <-
read.table(stringsAsFactors = FALSE, header = TRUE, text = "
nodeName nodeGroup nodeSize
Bob NorthAmerica 10
Alice NorthAmerica 10
Tom China 10
John Japan 10
")
subLinkList <-
read.table(stringsAsFactors = FALSE, header = TRUE, text = "
root children linkValue
0 1 1
0 2 1
0 3 1
")
network <- forceNetwork(Links = subLinkList, Nodes = subNodes,
Source = "root", Target = "children",
Value = "linkValue", NodeID = "nodeName",
Group = "nodeGroup",
opacity = 1, Nodesize = "nodeSize",
legend = TRUE)
network <- htmlwidgets::prependContent(network, htmltools::tags$h1("Title"))
network <- htmlwidgets::onRender(
network,
'function(el, x) {
d3.selectAll(".legend text").style("fill", "white");
d3.select("body").style("background-color", "#144370");
d3.select("h1").style("color", "red").style("font-family", "sans-serif");
d3.select("body")
.style("background-repeat", "no-repeat")
.style("background-position", "right bottom");
}'
)
network