For plotting a sankey diagram nodes and links are required. To get the nodes and links from a data frame one could use for example a count function from the package plyr and use it for each node to count the links between the neighbours but is there another elegant way?
example target, aim is to get nodes and links:
param1 | param2 | param3 |
a | b | d |
w | c | d |
a | b | d |
z | c | e |
#nodes:
nodes = data.frame("name" =
c(
a, #node 0
w, #node 1
z, #node 2
b, #node 3
c, #node 4
d, #node 5
e #node 6
))
#links
links = as.data.frame(matrix(c(
0, 3, 2, # from node 0, to node 3, freq
1, 4, 1,
2, 4, 1,
3, 5, 2,
4, 5, 1,
4, 6, 1,
),
byrow = TRUE, ncol = 3))