0
votes

linkdata:

  from    to  freq
  <int> <int> <int>
1     0     0     1
2     0     1    33
3     0     2    22
4     1     0    22
5     1     1     1
6     1     2    32

nodes = data.frame( names = unique(Data$names))%>%add_row(names = "other") 


sankeyNetwork( Links = as.data.frame( linkdata), Nodes = nodes, Source = "from",
                   Target = "to", Value = "freq" , NodeID = "names",
                   fontSize = 12, nodeWidth = 30)

The plot is not being displayed. I have added a new row in nodes based on an answer on StackOverflow even that did not work.

Data contains just some names that I want to name the labels in the sunkey plot.

  names
1 a
2 b
3 c
4 d
5 e
6 f
7 other
1
What is in Data? - CJ Yetman
They are a few labels (names) I want to give in the sankey plot - Manvitha Reddy

1 Answers

0
votes

May be there is something else going on that you're not telling us here? This works for me...

library(networkD3)

linkdata <- read.table(stringsAsFactors = F, header = T, text = 
'from  to  freq
0     0     1
0     1    33
0     2    22
1     0    22
1     1     1
1     2    32
')

Data <- read.table(stringsAsFactors = F, header = T, text = '
names
a
b
c
d
e
f
other
')

sankeyNetwork(Links = linkdata, Nodes = Data, Source = "from", Target = "to", 
          Value = "freq" , NodeID = "names", fontSize = 12, nodeWidth = 30)

enter image description here