我正在查看用于構建桑基圖的檔案和教程 
使用鏈接答案中的作業代碼:
links <-
df %>%
mutate(row = row_number()) %>% # add a row id
gather('col', 'source', -row) %>% # gather all columns
mutate(col = match(col, names(df))) %>% # convert col names to col nums
mutate(source = paste0(source, '_', col)) %>% # add col num to node names
group_by(row) %>%
arrange(col) %>%
mutate(target = lead(source)) %>% # get target from following node in row
ungroup() %>%
filter(!is.na(target)) %>% # remove links from last column in original data
select(source, target) %>%
group_by(source, target) %>%
summarise(value = n()) # aggregate and count similar links
# create nodes data frame from unque nodes found in links data frame
nodes <- data.frame(id = unique(c(links$source, links$target)),
stringsAsFactors = FALSE)
# remove column id from names
nodes$name <- sub('_[0-9]*$', '', nodes$id)
# set links data to the 0-based index of the nodes in the nodes data frame
links$source <- match(links$source, nodes$id) - 1
links$target <- match(links$target, nodes$id) - 1
sankeyNetwork(Links = links, Nodes = nodes, Source = 'source',
Target = 'target', Value = 'value', NodeID = 'name')
產生一個作業結果: 
我很欣賞作業代碼和我的代碼不同,但我看不到 sankeyNetwork 在哪里呼叫行號(即 x 軸)資料 - 沒有呼叫任何包含該資訊的變數。我想我可以讓我自己的代碼作業來準備資料,一旦我知道它需要看起來像什么。
uj5u.com熱心網友回復:
與中的所有函式一樣 
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/343355.html
標籤:javascript r d3.js htmlwidgets 网络d3
上一篇:帶有自定義React組件回傳物件Object的D3組織結構圖
下一篇:如何選擇與滿足條件相關的所有行
