简体   繁体   English

在 R 中创建一个具有集合节点位置和集中边的网络图,其中包含圆头和箭头

[英]Creating a network graph with set node positions and concentrated edges with both circleheads and arrowheads in R

I've been trying to find a way to replicate the following network graph format in R using DiagrammeR/GraphViz, but without success (ignore the thick black arrow on N1): https://i.stack.imgur.com/oHpQz.png我一直在尝试找到一种方法来使用 DiagrammeR/GraphViz 在 R 中复制以下网络图格式,但没有成功(忽略 N1 上的粗黑箭头): https://i.stack.imgur.com/oHpQz。 PNG

The graph is a directed graph and each edge in a certain direction either ends with an arrowhead (-->) if the edge value is positive, or a circle/odot (--o) if the edge value is negative.该图是一个有向图,如果边值为正,则某个方向上的每条边都以箭头 (-->) 结尾,如果边值为负,则以圆/点 (--o) 结尾。 Between a pair of nodes (ex. N1 -- A1), there can be an edge N1 --> A1 and an edge A1 --o N1, and these need to be concentrated so that the two edges look like one line with an arrowhead on one end and a circlehead on the opposite end (like this: o--->).在一对节点(例如 N1 -- A1)之间,可以有一条边 N1 --> A1 和一条边 A1 --o N1,这些需要集中起来,使两条边看起来像一条带一端为箭头,另一端为圆头(如:o--->)。 These cannot be parallel or look like two edges ideally.这些不能是平行的,也不能在理想情况下看起来像两条边。

Another requirement is that the nodes have to be in very specific positions and remain there throughout model simulations where edges might change.另一个要求是节点必须位于非常特定的位置,并且在边缘可能发生变化的 model 模拟中始终保持在那里。 From what I have tried and the documentation I have read, this is not possible to do in DOT format, but is possible in neato format.根据我的尝试和我阅读的文档,这不可能以 DOT 格式执行,但可以使用 neoto 格式。

This is where I get a problem.这是我遇到问题的地方。 In neato, I can align the nodes exactly where I want them by defining their x,y positions.在neato 中,我可以通过定义节点的x、y 位置将节点精确地对齐到我想要的位置。 However, when I use concentrate = true to create the o---> edge from two otherwise parallel edges, only one type of arrowhead remains.但是,当我使用 concent = true 从两个平行的边缘创建 o---> 边缘时,只剩下一种类型的箭头。 So an edge that's supposed to look like o---> ends up looking like ---> or o---.因此,应该看起来像 o---> 的边缘最终看起来像 ---> 或 o---。

This is not a problem in DOT format as concentrate = true does what I want it to do, but in DOT I cannot assign exact node positions.这在 DOT 格式中不是问题,因为 concent = true 可以满足我的要求,但在 DOT 中我无法分配确切的节点位置。 I have tried getting around this using node ranks but without much luck.我尝试过使用节点等级来解决这个问题,但运气不佳。 It seems to stack nodes I want in different ranks within the same rank.似乎将我想要的节点堆叠在同一等级内的不同等级中。 As well, concentrate = true doesn't seem to work for edges between nodes within the same rank, as it leaves them as two separate curved edges ---> and o--- without concentrating them.同样,concentrate = true 似乎不适用于同一等级内的节点之间的边缘,因为它将它们作为两个单独的弯曲边缘 ---> 和 o--- 而不集中它们。

The reason why I need this to work is because I'm running model simulations where the edges change, and I need to generate hundreds of such graphs.我需要这个工作的原因是因为我正在运行 model 模拟边缘发生变化,我需要生成数百个这样的图表。 For easy comparison, the nodes need to stay in the same place for consistency.为了便于比较,节点需要保持在同一位置以保持一致性。

This is the closest I could come up with using neato format (nodes are positioned the way I want but it's not showing the proper o---> for all the black edges minus self-edges; red edges are true one-way links): https://i.stack.imgur.com/YJBY7.jpg这是我使用neato格式所能想到的最接近的(节点以我想要的方式定位,但它没有显示正确的o--->所有黑色边缘减去自身边缘;红色边缘是真正的单向链接) : https://i.stack.imgur.com/YJBY7.jpg

If only the edges showed up as the proper o---> format, this would be perfect for my needs.如果只有边缘显示为正确的 o---> 格式,这将非常适合我的需要。 If you know of any way to fix this issue using DiagrammeR/GraphViz, or even another program, I would be so grateful.如果您知道使用 DiagrammeR/GraphViz 甚至其他程序解决此问题的任何方法,我将不胜感激。 Thanks!谢谢!

You probably don't need concentrate .你可能不需要专心 Look at arrowtail and dir ( https://www.graphviz.org/doc/info/attrs.html#d:arrowtail and https://www.graphviz.org/doc/info/attrs.html#d:dir ) and neato -n查看箭头目录https://www.graphviz.org/doc/info/attrs.html#d:arrowtailhttps://www.graphviz.org/doc/info/attrs.html#d:dir )和neato -n

digraph c {
  graph[label="can neato do the work?"]
  node[shape=circle]
  a [pos="100,100"]
  b [pos="200,100"]
  c [pos="300,100"]
  a->b [dir=both arrowtail=odot]
  c->c [dir=both arrowtail=odot arrowhead=none]
}

Giving:给予: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM