[英]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
。
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.