Reputation: 11
I have created a sankeyNetwork
using networkd3 in r. How can I change the color of flow lines or links? I would like to have the flow lines be the same color as the nodes.
Here is my code:
library(networkD3)
library(xlsx)
links <- read.xlsx("C:/Users/Administrator/Desktop/Book1.xlsx", sheetName = "links")
nodes <- read.xlsx("C:/Users/Administrator/Desktop/Book1.xlsx", sheetName = "nodes")
sankeyNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", Value = "value", NodeID = "Diagnosis", fontSize = 11, nodeWidth = 15, fontFamily = "arial", iterations = 0)
Upvotes: 1
Views: 1765
Reputation: 8848
No one here can reproduce your example because no one but you has access to the Book1.xlsx
file that is on your Desktop (read more here about making good reproducible examples). However, the help file for sankeyNetwork()
(you can access it by typing ?sankeyNetwork
in the R console) documents the LinkGroup
argument and gives an example of using it at the bottom.
LinkGroup - character string specifying the groups in the Links. Used to color the links in the network.
library(networkD3)
URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)
energy$links$energy_type <- sub(' .*', '', energy$nodes[energy$links$source + 1, 'name'])
sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name',
LinkGroup = 'energy_type')
Upvotes: 4