如何在R的边缘两侧绘制带有文本的有向网络图(通过iGraph,网络或其他软件包)?
变量(在向量自回归模型(VAR)中)位于节点中。
Granger因果关系(F统计数据的p值)位于边缘的两侧。我将p值放在每个箭头的开头。我通过增加强调来吸引近乎重要的因果关系。
我无法弄清楚如何通过iGraph或网络包或其他方式获得这样的网络图。
答案 0 :(得分:1)
阅读documentation on the igraph plot function似乎没有很多选项来操纵边标签,但你可以用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))
答案 1 :(得分:1)
您可以同时使用edge.label
和vertex.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)
edge.arrow.mode
可让您控制箭头。您可以使用edge.label.y
和edge.label.x
选项移动边缘标签。