介绍
采用networkD3
生成桑基图。
library(networkD3)
nodes <- data.frame(name = c("Raw Material A", "Raw Material B", "Raw Material C",
"Processed Material A1", "Processed Material B1",
"Component A1-B1", "Component B1-C1",
"Final Product A", "Final Product B"))
links <- data.frame(source = c(0, 1, 2, # Raw materials to processed materials
0, 1, 1, 2, # Processed materials to components
3, 4, # Components to final products
5, 6),
target = c(3, 4, 6, # Processed materials
5, 5, 6, 6, # Components
7, 8, # Final products
7, 8),
value = c(10, 20, 30, # Values for raw to processed
15, 25, 35, 30, # Values for processed to components
20, 30, # Values for components to final
40, 50)) # Final values
links$source <- as.integer(links$source)
links$target <- as.integer(links$target)
sankey <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
fontSize = 12, nodeWidth = 30)
sankey
网友评论