I am working on making a sankey diagram in R but having trouble with the meaning behind the node names.
Below is an example that I found online:
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= 12, nodeWidth = 30)
The dataset I am using is below:
source<-c('EASTERN PARKWAY', 'CONEY ISLAND AVENUE', 'ATLANTIC AVENUE', 'ATLANTIC AVENUE','ATLANTIC AVENUE','ATLANTIC AVENUE',
'AVENUE P', 'BAY PARKWAY', 'BUFFALO AVENUE', 'FLATBUSH AVENUE', 'PROSPECT EXPRESSWAY', 'SAINT JOHNS PLACE',
'6 AVENUE', '65 STREET', '65 STREET', '65 STREET', 'ATLANTIC AVENUE', 'ATLANTIC AVENUE', 'ATLANTIC AVENUE', 'CONEY ISLAND AVENUE')
target<-c('BUFFALO AVENUE', 'AVENUE J', 'CLASSON AVENUE', 'EASTERN PARKWAY', 'HICKS STREET', 'LOGAN STREET',
'EAST 18 STREET', 'CROPSEY AVENUE', 'EASTERN PARKWAY', 'AVENUE V', 'CHURCH AVENUE', 'ROCHESTER AVENUE',
'ATLANTIC AVENUE', '17 AVENUE', '18 AVENUE', 'BAY PARKWAY', 'NEVINS STREET', 'UTICA AVENUE', 'VANDERBILT AVENUE', 'AVENUE P')
value<-c(8,5,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3)
df<-data.frame(source, target, value)
df
source target value
1 EASTERN PARKWAY BUFFALO AVENUE 8.00
2 CONEY ISLAND AVENUE AVENUE J 5.00
3 ATLANTIC AVENUE CLASSON AVENUE 4.00
4 ATLANTIC AVENUE EASTERN PARKWAY 4.00
5 ATLANTIC AVENUE HICKS STREET 4.00
6 ATLANTIC AVENUE LOGAN STREET 4.00
7 AVENUE P EAST 18 STREET 4.00
8 BAY PARKWAY CROPSEY AVENUE 4.00
9 BUFFALO AVENUE EASTERN PARKWAY 4.00
10 FLATBUSH AVENUE AVENUE V 4.00
11 PROSPECT EXPRESSWAY CHURCH AVENUE 4.00
12 SAINT JOHNS PLACE ROCHESTER AVENUE 4.00
13 6 AVENUE ATLANTIC AVENUE 3.00
14 65 STREET 17 AVENUE 3.00
15 65 STREET 18 AVENUE 3.00
16 65 STREET BAY PARKWAY 3.00
17 ATLANTIC AVENUE NEVINS STREET 3.00
18 ATLANTIC AVENUE UTICA AVENUE 3.00
19 ATLANTIC AVENUE VANDERBILT AVENUE 3.00
20 CONEY ISLAND AVENUE AVENUE P 3.00
Does someone know how to reproduce the sankey diagram above with this data? I can't seem to figure out how the nodes come into play. Any help would be great thanks!