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
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.