Story
While attempting to recreate a Sankey graph similar to the one shown in the image below, I aimed to assign specific values (10, 20, 30, 40) to the paths connecting different nodes.
https://i.sstatic.net/U3erS.png
My Approach
Initially, I used the Python Plotly library for this task. However, I discovered that Plotly does not provide direct support for setting values along the links or paths of a Sankey graph. Subsequently, I switched to R due to its wider range of resources available. Nevertheless, I encountered the same issue even in R. Despite consulting various tutorials and Q&A threads on Stack Overflow related to Sankey graphs in R (such as this one), I have been unable to find a solution where the path values are displayed.
Main Concern
I am seeking guidance on how to showcase values on the links/paths of a Sankey Graph using R.
Please Note: The questions on Stack Overflow mentioned here (link1 and link2) appear relevant, but I am struggling to implement their solutions in my own code snippets.
Sample Code Snippet (excerpted from here)
# install.packages('networkD3')
library(networkD3)
nodes = data.frame("name" =
c("Node A", # Node 0
"Node B", # Node 1
"Node C", # Node 2
"Node D"))# Node 3
links = as.data.frame(matrix(c(
0, 1, 10, # Each row represents a link. The first number
0, 2, 20, # represents the node being conntected from.
1, 3, 30, # the second number represents the node connected to.
2, 3, 40),# The third number is the value of the node
byrow = TRUE, ncol = 3))
names(links) = c("source", "target", "value")
sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize= 50, nodeWidth = 30)