use*_*345 3 network-programming r igraph sna
我正在R中使用igraph进行网络分析。我想在图中的每条线上显示一个edge属性。下面是一个例子
df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)
plot(pg)
Run Code Online (Sandbox Code Playgroud)
我希望“ wt”功能的值显示在行中的每个节点之间,或者最好显示在行中断处的小缝隙中。
有可能做到这一点吗?
使用参数edge.label分配边缘的标签,我曾经使用过-可能是错误的-nod $ wt。当然,您可以分配其他标签。
您可以使用以下代码:
# load the package
library(igraph)
# your code
df <- data.frame(a = c(0,1,2,3,4),b = c(3,4,5,6,7))
nod <- data.frame(node = c(0:7),wt = c(1:8))
pg <- graph_from_data_frame(d = df, vertices = nod,directed = F)
# plot function with edge.label added
plot(pg, edge.label = nod$wt)
Run Code Online (Sandbox Code Playgroud)
请让我知道这是否是您想要的。