R networkD3 color node stroke for radialNetwork()

二次信任 提交于 2019-12-01 10:59:37

Not directly... does not support that capability. However, you can inject your own JavaScript into that attribute.

For example, if you have a vector of color names in the proper order, you could convert that to a JavaScript array (in the form: ["red", "blue", "green"]) and use the JS function from the htmlwidget package to build a function to pass through the nodeStroke argument.

colorVector <- c("black", "red", "blue", "green", "orange", 
    rep("red", 5), rep("blue", 5), rep("green", 4), rep("orange", 4),
    rep("red", 11), rep("blue", 14), rep("green", 14), rep("orange", 11))

jsarray <- paste0('["', paste(colorVector, collapse = '", "'), '"]')
nodeStrokeJS <- JS(paste0('function(d, i) { return ', jsarray, '[i]; }'))

radialNetwork(ToListExplicit(Data_tree, unname = TRUE ), 
    linkColour = "#ccc",
    nodeColour = "#fff",
    nodeStroke = nodeStrokeJS,
    textColour = "#cccccc")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!