R - 对角线网络中的 JS 数组
R - JS array in diagonalnetwork
我的问题是关于:
每当我创建和使用颜色向量(上下文在 link 的回答中给出)时,diagonalNetwork()
会错误地分配节点颜色。
有什么方法可以知道 diagonalNetwork()
是如何重新排列输入的数据的?网络标签和结构正确。只有颜色不是。
按级别应用颜色,然后按数据最初的顺序应用。在此示例中,颜色排序为根为黑色,省份为红色,城市为蓝色。
library(networkD3)
CanadaPC <- list(name = "Canada", children =
list(list(name = "Newfoundland",
children = list(list(name = "St. John's"))),
list(name = "PEI",
children = list(list(name = "Charlottetown"))),
list(name = "Nova Scotia",
children = list(list(name = "Halifax"))),
list(name = "New Brunswick",
children = list(list(name = "Fredericton"))),
list(name = "Quebec",
children = list(list(name = "Montreal"),
list(name = "Quebec City"))),
list(name = "Ontario",
children = list(list(name = "Toronto"),
list(name = "Ottawa"))),
list(name = "Manitoba",
children = list(list(name = "Winnipeg"))),
list(name = "Saskatchewan",
children = list(list(name = "Regina"))),
list(name = "Nunavuet",
children = list(list(name = "Iqaluit"))),
list(name = "NWT",
children = list(list(name = "Yellowknife"))),
list(name = "Alberta",
children = list(list(name = "Edmonton"))),
list(name = "British Columbia",
children = list(list(name = "Victoria"),
list(name = "Vancouver"))),
list(name = "Yukon",
children = list(list(name = "Whitehorse")))
))
colorVector <- c("black", rep("red", 13), rep("blue", 16))
jsarray <- paste0('["', paste(colorVector, collapse = '", "'), '"]')
nodeStrokeJS <- JS(paste0('function(d, i) { return ', jsarray, '[i]; }'))
diagonalNetwork(List = CanadaPC, nodeStroke = nodeStrokeJS)
我的问题是关于:
每当我创建和使用颜色向量(上下文在 link 的回答中给出)时,diagonalNetwork()
会错误地分配节点颜色。
有什么方法可以知道 diagonalNetwork()
是如何重新排列输入的数据的?网络标签和结构正确。只有颜色不是。
按级别应用颜色,然后按数据最初的顺序应用。在此示例中,颜色排序为根为黑色,省份为红色,城市为蓝色。
library(networkD3)
CanadaPC <- list(name = "Canada", children =
list(list(name = "Newfoundland",
children = list(list(name = "St. John's"))),
list(name = "PEI",
children = list(list(name = "Charlottetown"))),
list(name = "Nova Scotia",
children = list(list(name = "Halifax"))),
list(name = "New Brunswick",
children = list(list(name = "Fredericton"))),
list(name = "Quebec",
children = list(list(name = "Montreal"),
list(name = "Quebec City"))),
list(name = "Ontario",
children = list(list(name = "Toronto"),
list(name = "Ottawa"))),
list(name = "Manitoba",
children = list(list(name = "Winnipeg"))),
list(name = "Saskatchewan",
children = list(list(name = "Regina"))),
list(name = "Nunavuet",
children = list(list(name = "Iqaluit"))),
list(name = "NWT",
children = list(list(name = "Yellowknife"))),
list(name = "Alberta",
children = list(list(name = "Edmonton"))),
list(name = "British Columbia",
children = list(list(name = "Victoria"),
list(name = "Vancouver"))),
list(name = "Yukon",
children = list(list(name = "Whitehorse")))
))
colorVector <- c("black", rep("red", 13), rep("blue", 16))
jsarray <- paste0('["', paste(colorVector, collapse = '", "'), '"]')
nodeStrokeJS <- JS(paste0('function(d, i) { return ', jsarray, '[i]; }'))
diagonalNetwork(List = CanadaPC, nodeStroke = nodeStrokeJS)