Customising sankey diagram in networkD3

Hi R coders,

Looking for some help with my sankey diagram.

I'm using networkD3 and created this lovely diagram but am struggling to customize it. I am looking to make the nodes' shape a circle rather than a rectangle and also, make it collapse the linked output nodes when pressing the source nodes.

If anyone can help, it would be greatly appreciated.

Code below:

install.packages("xlsx")
install.packages("d3Network")
install.packages("networkD3")
install.packages("readxl")
install.packages("RCurl")
install.packages("RColorBrewer")

library(xlsx)
library(d3Network)
library(readxl)
library(RCurl)
library(networkD3)
library(ColorBrewer)

links2 <- read_xlsx("C:/Users/astaneva/Desktop/Sankey.xlsx", sheet = "links")
nodes2 <- read_xlsx("C:/Users/astaneva/Desktop/Sankey.xlsx", sheet = "nodes")

sankeyNetwork(Links = links2, Nodes = nodes2, Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontSize = 14, nodeWidth = 12, units = "£",
fontFamily = "sans-serif", iterations = 0)

Ta!

FYI... no one will be able to reproduce your example without access to your "Sankey.xlsx".

That being said, networkD3 is not designed to facilitate that level of customization. In order to achieve that, one would have to heavily modify the underlying JavaScript that is included in the package.

Thanks cjyetman, what other packages could you recommend for the sankey diagram?

I know that there are other packages available that make sankey plots, but I can't recommend any because networkD3 is the only one I am familiar with.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.