这个问题在这里已有答案:
看看Confirmed
和Unconfirmed
上面的输出是如何重叠的?我不希望这样。似乎最终值Vendor
,TBD
,Internal
,No Problem Found
按降序排序,导致此问题。
理想情况下,Unconfirmed -> TBD
的流量应该是图像底部的直线。奇怪的是,我运行脚本的前几次就是它出现的样子!但它不再出现这种方式了?
有什么办法可以做我想要的吗?这是我的代码:
library(tidyverse)
library(networkD3)
# Generate Sankey Data ---------------------------------------------------------
source <- c("Barcode Scanner", "Cell Enrichment", "Consumables", "Contamination", "Cosmetic", "Dimensional", "Display", "Heaters", "Labels", "Missing Component", "Pumps", "Vials", "Barcode Scanner", "Cell Enrichment", "Consumables", "Contamination", "Cosmetic", "Dimensional", "Display", "Heaters", "Labels", "Missing Component", "Pumps", "Vials", "Confirmed", "Confirmed", "Confirmed", "Unconfirmed")
target <- c("Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Vendor", "Internal", "No Problem Found", "TBD")
values <- c("18", "8", "20", "15", "7", "17", "20", "14", "9", "16", "11", "20", "8", "7", "8", "8", "8", "6", "2", "5", "4", "8", "6", "6", "98", "53", "24", "76")
# Setup Sankey Network ----------------------------------------------------------
nodes <- data.frame(name = unique(c(source, target)))
links <- data.frame(source = match(source, nodes$name) - 1,
target = match(target, nodes$name) - 1,
value = values)
sn <- sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "Complaints", fontSize = 12, nodeWidth = 20)
# Fix issues with Firefox rendering --------------------------------------------
htmlwidgets::onRender(sn, 'document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')
As explained in a similar question这提供了解决方案:iterations = 0
library(tidyverse)
library(networkD3)
# Generate Sankey Data ---------------------------------------------------------
source <- c("Barcode Scanner", "Cell Enrichment", "Consumables", "Contamination", "Cosmetic", "Dimensional", "Display", "Heaters", "Labels", "Missing Component", "Pumps", "Vials", "Barcode Scanner", "Cell Enrichment", "Consumables", "Contamination", "Cosmetic", "Dimensional", "Display", "Heaters", "Labels", "Missing Component", "Pumps", "Vials", "Confirmed", "Confirmed", "Confirmed", "Unconfirmed")
target <- c("Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Confirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Unconfirmed", "Vendor", "Internal", "No Problem Found", "TBD")
values <- c("18", "8", "20", "15", "7", "17", "20", "14", "9", "16", "11", "20", "8", "7", "8", "8", "8", "6", "2", "5", "4", "8", "6", "6", "98", "53", "24", "76")
# Setup Sankey Network ----------------------------------------------------------
nodes <- data.frame(name = unique(c(source, target)))
links <- data.frame(source = match(source, nodes$name) - 1,
target = match(target, nodes$name) - 1,
value = values)
sn <- sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "Complaints", fontSize = 12, nodeWidth = 20,
iterations = 0)
# Fix issues with Firefox rendering --------------------------------------------
htmlwidgets::onRender(sn, 'document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')