与另一弧重叠时自动弯曲弧 [英] Automatically curving an arc when it is overlapping with another one

查看:86
本文介绍了与另一弧重叠时自动弯曲弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会自动生成其节点需要固定位置的图形.例如:

I am automatically generating graphs whose nodes need to be in fixed positions. For example:

实际上从节点V4到节点V16都有一条弧,但是我们看不到它,因为从V4到V10以及从V10到V16也有弧.

There is actually an arc from node V4 to node V16, but we annot see it because there are also arcs from V4 to V10 and from V10 to V16.

请注意,节点和圆弧都是自动生成的,并且位置可能会有所不同,因此我需要一种自动的方法来弯曲隐藏在其他圆弧后面的圆弧.

Note that both the nodes and the arcs are generated automatically, and that the positions may vary, so I would need an automated way to curve arcs that are hidden behind other arcs.

还请注意,以下解决方案均无效: igraph:解决紧密重叠的节点; 使用igraph,如何在以下情况下强制弯曲箭头指向相反的方向.第一个只是以某种方式放置de节点,但是我的节点需要固定.第二个简单地处理成对的节点,该节点对具有两个连接相反方向的弧.

Also note that none of these solutions are valid: igraph: Resolving tight overlapping nodes ; Using igraph, how to force curvature when arrows point in opposite directions. The first one simply places de nodes in a certain way, but my nodes need to be fixed. The second one simply deals with pairs of nodes that have two arcs connecting them going in the opposite direction.

更新:该图的构造是该图的学习过程的结果,该学习过程形成了贝叶斯网络使用bnlearn库,因此我不太确定如何制作可复制的示例.节点的位置是固定的,因为它们代表位置.我实际上需要一些魔术,对重叠弧的检测:如果两个弧重叠,则稍微弯曲其中一个以便可以看到.从链接的问题中我知道弯曲弧线是一种选择,所以我想也许可以实现这种魔术

UPDATE: The construction of the graph is the result of the learning process of the graph that forms a Bayesian Network using bnlearn library, so I am not very sure how could I produce a reproducible example. The positions of the nodes are fixed because they represent positions. I actually need some magic, some kind of detection of overlapping arcs: If two arcs overlap, curve one of them slightly so that it can be seen. I know from the linked questions that curving an arc is an option, so I thought maybe this kind of magic could be achieved

推荐答案

一种解决方案是使用qgraph包.在下面的示例中,它会自动弯曲双向边缘:

One solution would be to use the qgraph package. In the example below it automatically curves the bidirectional edges:

library(igraph)
library(qgraph)

# the raster layout
layout <- cbind(1:3, rep(1:3, each = 3))
# fully connected network
adj <- matrix(1, 9, 9)

# plot directed and undirected network
layout(matrix(1:2, 1, 2))
qgraph(adj, layout = layout, directed = FALSE, title = "undirected")
qgraph(adj, layout = layout, directed = TRUE, title = "directed") # automatically curves the bidirectional arrows

要将igraph对象转换为qgraph可以使用的对象,您只需要一个边列表或邻接矩阵即可:

To convert an igraph object to something qgraph can use, all you need is an edgelist or adjacency matrix:

g <- make_ring(9)
edgeList <- do.call(rbind, igraph::get.adjedgelist(g))
qgraph(edgeList)

如果还希望包括轴,则可以使用axis()进行操作,因为qgraph使用基本图形.但是,您可能还必须修改par(),以使其看起来不错.

If you also want to include the axes, you can do so using axis() since qgraph uses base graphics. However, you probably have to tinker with par() as well to make it look nice.

这篇关于与另一弧重叠时自动弯曲弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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