Colouring scheme in networkD3 vs igraph

后端 未结 1 1422
后悔当初
后悔当初 2021-01-16 10:01

I have a network where I have characterised each of the nodes with previous analysis- and have assigned the colours as follows:

plot.igraph(g, layout=layout.         


        
相关标签:
1条回答
  • 2021-01-16 10:31

    You can pass Javascript code through with the JS() function that comes with the networkD3 package. In Javascript, you can use hex code to specify colors. Here is an example:

    YourColors <- 'd3.scaleOrdinal().range([ "#FFA500", "#4169E1",  "#32CD32",
                                             "#FFC0CB", "#8A2BE2", "#FF6347"]);'
    
    forceNetwork(Links = data$links, Nodes = data$nodes, 
                 Source = 'source', Target = 'target', 
                 NodeID = 'value', Nodesize = 'size', Group = "group",
                 ######################### 
                 colourScale = JS(YourColors), 
                 #########################
                 zoom = T, legend = T, opacityNoHover = TRUE)
    

    If you want to tie specific colors to specific variables, you can use

        YourColors <- 'd3.scaleOrdinal()
                      .domain(["variable1", "variable2", "variable3"])
                      .range(["#7FFF00", "#A52A2A", "#E6E6FA"])'
    
    0 讨论(0)
提交回复
热议问题