在R中使用forceNetwork变得疯狂:没有显示边缘 [英] Going crazy with forceNetwork in R: no edges displayed

查看:341
本文介绍了在R中使用forceNetwork变得疯狂:没有显示边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个星期以来,我一直在尝试使用R中的 networkD3 软件包绘制网络. simpleNetwork函数正常工作,但是它不允许过多控制图形的外观. forceNetwork功能用于此目的:显示具有丰富视觉特征的图形.

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 control over the appearance of the graph. The forceNetwork function is there for this purpose: display graph with enriched visual features.

我遇到的问题与问题.我已经仔细阅读了软件包文档,并尝试了上述线程中提出的解决方案,但是没有运气:我得到的只是一堆节点云,没有连接它们的边.

The problem I have is pretty much the same exposed in this question. I have carefully read the package documentation, and tried the solution proposed in the above thread, with no luck: all I get is a cloud of nodes with no edges linking them.

这是我的data.frame:

edg

Gene1 Gene2 Prob
  1    22    3
  2    22    6
  3    22    6
  4    22    9
  5    22    3
  6    22    4
  7    22    8
  8    22    4
  9    22    6
 10    22    8
 11    22    6
 12    22   10
 13    22    6
 14    22    3
 15    22    6
 16    22    6
 17    22    0
 18    22    4
 19    22    6
 20    22    4

vert

Symbol Chr Expr
   1   21    9
   2   17   10
   3   17    0
   4   20    0
   5    6    9
   6    5   11
   7   12    0
   8    1   20
   9   17   11
  10   17    7
  11   17   11
  12   10    0
  13   17    0
  14    7    7
  15   17    6
  16   17    0
  17    2    5
  18    5   10
  19   17   10
  20   17    9
  21   12    4
  22    3    2

好吧,这导致上面提到的没有边缘的节点云.如果我用在节点上放置的实际标签来更改符号"列,则也是同样的事情(按照软件包的要求,遵循链接"表的顺序).

Well, this results in the above mentioned cloud of nodes with no edges. Same thing if I change 'Symbol' column with actual labels I'd put on the nodes (respecting the order of Links' table, as required by the package).

请注意,该软件包通过示例说明了此功能的使用您打开使用的数据集( MisLinks,MisNodes ),除节点标签外,它们的内容与我的相同.运行相同的示例是可行的.不运行我的数据.

Note that the package illustrates the use of this function with this example, and if you open the datsets used (MisLinks, MisNodes), their content is the same as mine, except for the labels of the nodes. Running that very same example works; running with my data does not.

这是我用来绘制网络图的功能:

Here is the function I use to plot the network:

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

其他所有属性均正确显示(节点大小,图例,颜色),但我始终看不到任何边缘.我的数据集中某处肯定有一个错误,我无法以任何方式找到它.

Every other property is correctly displayed (node size, legend, colours), but I keep seeing no edges. There must be a mistake somewhere in my datasets, which I cannot find in any way.

推荐答案

我遇到了同样的问题(simpleNetwork正常工作,forceNetwork首先仅显示节点且没有边缘,然后再完全不显示).

I was having the same problem (simpleNetwork working normally, forceNetwork first displaying only nodes & no edges, then subsequently no display at all).

问题(大概是在从0开始编号的重建数据帧时修复的")是您原来的Links数据edg,从1开始而不是0?

The problem (which you presumably fixed when you "rebuilt dataframes starting numbering from 0") was your original Links data, edg, starting from 1 instead of 0?

networkD3文档 http://christophergandrud.github.io/networkD3/具有此功能注意:

The networkD3 documentation, http://christophergandrud.github.io/networkD3/, has this note:

注意:您可能已经习惯了R的基于1的编号(即,R的计数从1开始).但是,networkD3图是使用基于0的JavaScript创建的.因此,您的数据链接需要从0开始.

Note: You are probably used to R’s 1-based numbering (i.e. counting in R starts from 1). However, networkD3 plots are created using JavaScript, which is 0-based. So, your data links will need to start from 0.

重新.我最初也认为可能是问题的不正确数据类型,我测试了强制转换所有不同的列(NodeID的factor变量除外)as.numeric vs as.integer-但是现在将我的数据更正为基于0而不是从1开始,我的forceNetwork显示器可以正常使用这两种数据类型.

Re. incorrect data types which I also originally thought might be the problem, I tested casting all the different columns (except the factor variable for the NodeID) as.numeric vs as.integer - however having now corrected my data to be 0-based instead of 1-based, my forceNetwork display works normally with either data type.

希望这会有所帮助!

这篇关于在R中使用forceNetwork变得疯狂:没有显示边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆