如何重新排列igraph图中的边缘顺序? [英] How can I rearrange the order of edges in an igraph plot?

查看:144
本文介绍了如何重新排列igraph图中的边缘顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在igraph中绘制网络图,以通过突出显示某些重要边缘的颜色与其他颜色不同的方式来突出显示这些重要边缘.对于大型图形,它们通常会被埋在其他图形之下.例如:

I'm trying to make a network plot in igraph that highlights certain important edges by coloring them differently than the others. For large graphs, they often get buried under the others. For example:

library(igraph)
test <- barabasi.game(200,m=2)
E(test)$color <- "gray"
E(test)[1]$color <- "red"
sort(order(E(test)$color)[E(test)],decreasing=TRUE)
plot(test,
     vertex.label=NA,
     vertex.shape="none",
     vertex.size=0,
     edge.arrow.mode=0,
     edge.width=2) 

给我一​​个情节,其中单个红色边缘在底部. 如果我选择给编号较高的边缘(而不是#1)着色,则它更有可能不会被掩埋.

gives me a plot where the single red edge is at the bottom. If I choose to color a higher-numbered edge (rather than #1) it has a better chance of not being buried.

所以在我看来,一种选择是以某种方式重新排列边缘.我尝试过

So it seems to me that one option is to somehow re-order the edges. I tried

E(test) <- E(test)[order(E(test)$color)]

但是这使我出现无效索引"错误.关于我还应该尝试什么的任何想法?

but that gets me an "invalid indexing" error. Any ideas about what else I should try?

推荐答案

igraph按照它们在图形的边缘列表中出现的顺序绘制边缘,所以您说对了,ID较高的边缘将在边缘上绘制较低的ID.不幸的是,igraph没有提供一种简单的方法来对图的边缘进行重新排序(尽管它具有名为permute.vertices的功能,该功能可以让您置换顶点),所以我现在唯一想到的方法是您需要构造另一个图,其中边缘按正确顺序"排列. make_graph确保边缘按照指定的顺序完全存储在图形中,我认为graph_from_data_frame也是这样.

igraph plots the edges in the order they appear in the graph's edge list, so you are right, edges with higher IDs will be drawn on top of the edges with lower IDs. Unfortunately igraph does not provide an easy way to reorder the edges of the graph (although it has a function named permute.vertices, which will allow you to permute the vertices), so the only way I can think of right now is that you need to construct another graph in which the edges are in the "right order". make_graph ensures that the edges are stored in the graph exactly in the order you specify them, and I think so does graph_from_data_frame.

另一种选择(如果您不想重构整个图)是绘制两次图:首先绘制不太重要"的边,并将重要边的宽度设置为零,然后再进行绘制.在顶部绘制重要的边缘.

Another option (if you don't want to reconstruct the entire graph) is to plot the graph twice: first you plot the "not-so-important" edges and set the width of the important ones to zero, then you plot the important edges on top.

如果您希望在即将发布的igraph版本中支持边缘置换,请提交功能请求在Github上.

If you would like edge permutations to be supported in an upcoming version of igraph, please file a feature request on Github.

这篇关于如何重新排列igraph图中的边缘顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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