简体   繁体   English

如何用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)?

How to draw a directed network graph with texts on both sides of edges in R (via iGraph, network or some other package)? 如何用R(通过iGraph,network或其他软件包)在R的边缘两边绘制文本的有向网络图?

有向网络图,边缘两边都有文字

Variables (in vector autoregressive model (VAR)) are in nodes. 变量(在向量自回归模型(VAR)中)在节点中。

The Granger causalities (p values of the F statistics) are on both sides of edges. 格兰杰因果关系(F统计的p值)在边的两侧。 I put p values to the beginning of each arrow. 我将p值放在每个箭头的开头。 I draw near-significant causalities with added emphasize. 我加重强调,得出了近乎重大的因果关系。

I could not figure out how to get such a network diagram via iGraph or network package or something else. 我不知道如何通过iGraph或网络程序包或其他方法获得这样的网络图。

Reading the documentation on the igraph plot function it seems that there is not a lot of options to manipulate edges labels but you can manipulate vertex labels with label.dist and label.degree for example.. You can do something like that: 阅读有关igraph绘图功能文档,似乎没有很多选择可以操作边缘标签,但是您可以使用label.dist和label.degree等操作顶点标签。您可以执行以下操作:

g <- graph.empty(n = 3) 
g <- graph(c(1, 2, 3, 2, 1, 3), directed = TRUE)
labels <- c("A", "B", "C", "D", "E", "F")
coords <- matrix(c(1, 1, 2, 2, 3, 3), nrow = 3)
plot(g, layout = coords, vertex.label = labels, vertex.label.dist = 3.5, vertex.label.degree = c(-pi/4, pi/2, pi, -pi/2, 0, 3*pi/4))

Graph 图形

You can use the edge.label and vertex.label options together. 可以同时使用edge.labelvertex.label选项。

library(igraph)
el <- data.frame(sender = c("lnbist1f","lnbist1f","lnbist1f",
                            "kur1f","kur1f","kur1f",
                            "lnaltin","lnaltin","lnaltin",
                            "mfaiz1f","mfaiz1f","mfaiz1f"),
                 receiver = c("mfaiz1f","lnaltin","kur1f",
                              "lnbist1f","lnaltin","mfaiz1f",
                              "mfaiz1f","lnbist1f","kur1f",
                              "lnbist1f","lnaltin","kur1f"),
                 pval = c(0.5,0.6,0.1, #I just typed random p-vals here
                          0.45,0.88,0.24,
                          0.12,0.51,0.99,
                          0.001,0.056,0.123)
                 )
arrows = c(2,1,0,0,1,1,1,0,0,2,1,1)
el <- as.matrix(el)
g <- graph_from_edgelist(el[,1:2], directed = T)
coordinates <- matrix(c(4, 4, 1, 1, 4, -2,7,1), nrow = 4, byrow=TRUE)
plot(g, edge.label=el[,3], 
     vertex.shape="crectangle", 
     vertex.size=45,
     edge.arrow.mode=arrows,
     layout = coordinates)

The edge.arrow.mode lets you control the arrowheads. edge.arrow.mode可让您控制箭头。 You can move the edge labels around with edge.label.y and edge.label.x options. 您可以使用edge.label.yedge.label.x选项来移动边缘标签。

图形图

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

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