简体   繁体   English

r中的igraph包:如何标记有向无环图的边

[英]igraph package in r: How to label edges for a directed-acyclic-graph

I am very new to r and programming, so my knowledge is limited. 我对r和编程非常陌生,所以我的知识有限。 I am using the igraph package and tkplot to make and present a directed acyclic graph. 我正在使用igraph包和tkplot制作并展示有向无环图。 I managed to make a graph and I am trying to figure out how to add labels to each edge. 我设法制作了一张图,并且试图弄清楚如何在每个边缘上添加标签。 My goal is to have a small annotation on the line between each vertices/vertex explaining their relationship. 我的目标是在每个顶点/顶点之间的行上有一个小的注释,以说明它们之间的关系。

I have tried inserting text as shown below: 我尝试插入文本,如下所示:

text(-1, 0,"[1, 2, 3]")
text(0, 1,"[3, 5, 6]")

However, this text does not transfer to out of r with tkplot and is hard to line up with the lines between vertices. 但是,此文本不会通过tkplot转移到r tkplot ,并且很难与顶点之间的线tkplot

this code gave me the exact graph I want minus the text between vertices. 这段代码为我提供了我想要的确切图形,减去了顶点之间的文本。


g <- graph.formula("ATB" -+ "Microbiome",
                   "Microbiome" -+ "Inflammation A" -+ "IO Response",
                   "Microbiome" -+ "Inflammation B" -+ "IO Response",
                   "Microbiome" -+ "IO Response",
                   "ATB" -+ "IO Response",
                   "Corticosteroids" -+ "IO Response",
                   "Corticosteroids" -+ "Microbiome",
                   "PPI" -+ "IO Response",
                   "PPI" -+ "Microbiome",
                   "H2B" -+ "IO Response",
                   "H2B" -+ "Microbiome",
                   "NSAIDs" -+ "Microbiome",
                   "NSAIDs" -+ "Inflammation B",
                   "NSAIDs" -+ "IO Response",
                   "Corticosteroids" -+ "Inflammation A",
                      simplify = TRUE)

plot.igraph(g, size = 90)

tkplot(g)

You can add labels to the edges by assigning an attribute "label" to each edge. 您可以通过为每个边缘分配属性“标签”来为边缘添加标签。 You don't say what you want as the labels, so I arbitrarily assigning a letter code to each edge. 您没有说出要用作标签的内容,所以我随意给每个边缘分配一个字母代码。 Also, your plot statement includes a "size" parameter. 此外,您的绘图语句还包含一个“大小”参数。 That causes an error so I left it off. 这会导致错误,所以我将其保留。 Did you mean "vertex.size"? 您是说“ vertex.size”吗?

E(g)$label = LETTERS[1:ecount(g)]
plot(g)

带有标记边的图形

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

相关问题 如何用R(通过iGraph,network或其他软件包)在R的边缘两边绘制文本的有向网络图? - How to draw a directed network graph with texts on both sides of edges in R (via iGraph, network or some other package)? 使用igraph,网络或其他R包计算有向无环图的所有生成树 - Compute ALL spanning trees of a directed acyclic graph using igraph, network, or other R package 如何在R中绘制有向无环格子图 - How to plot directed acyclic lattice graph in R 在 igraph(R 包)中反转有向图(转置图)中的边 - Invert edges in a directed graph (transpose graph) in igraph (R packages) 如何在R(igraph包)中显示图形的加权边之和? - How to display the sum of weighted edges of a graph in R (igraph package)? 如何使用 igraph R 包比较两个图以识别两个图之间相同/不同边的数量 - How to compare two graphs to Identify number of same/different edges between two graph using igraph R package 在R中使用有向边生成图形 - Building a Graph with Directed Edges in R 多个有向边igraph - Multiple directed edges igraph 如何在 igraph R 中的图形组件之间添加边 - How to add a edges between component of a graph in igraph R 使用R中的igraph更快地向图中的节点添加边 - adding edges to nodes in a graph faster with igraph in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM