R networkD3 color node stroke for radialNetwork()

后端 未结 1 685
温柔的废话
温柔的废话 2021-01-14 13:58

The networkd3 package contains some very nice functions for creating the obvious networks. Different functions have different arguments, so this questions is specifically in

1条回答
  •  耶瑟儿~
    2021-01-14 14:51

    Not directly... networkd3 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")
    

    0 讨论(0)
提交回复
热议问题