Going crazy with forceNetwork in R: no edges displayed

后端 未结 4 942
后悔当初
后悔当初 2021-01-20 17:44

I\'ve been trying to plot a network using networkD3 package in R for a week now. The simpleNetwork function works normally, but it doesn\'t allow much

4条回答
  •  暖寄归人
    2021-01-20 18:25

    I met the same problem, but fixed it by setting the factor levels of source and target to be consistent with node names before transferring into numeric:

    edg$Gene1<-factor(edg$Gene1,levels=vert$Symbol)
    edg$Gene2<-factor(edg$Gene2,levels=vert$Symbol)
    edg$source<-as.numeric(edg$Gene1)-1
    edg$target<-as.numeric(edg$Gene2)-1
    

    so that source and target vectors have consistent factor levels as node names (vert$Symbol), then

    forceNetwork( Links = edg, Nodes = vert, Source = "source", Target = "target", 
              Value = "Prob", NodeID = "Symbol", Group = "Chr", opacity = 0.7,
              colourScale = "d3.scale.category20b()", Nodesize = "Expr", zoom = T,
              legend = T )
    

    works for me.

    Hope this is helpful.

提交回复
热议问题