【发布时间】:2020-01-18 23:56:29
【问题描述】:
我有以下 R 代码:
library('igraph')
nodes <- c('a','b','c','d')
x <- c(0,1,2,3)
y <- c(0,1,2,3)
from <- c('a','b','c')
to <- c('b','c','d')
NodeList <- data.frame(nodes, x ,y)
EdgeList <- data.frame(from, to)
plot(graph_from_data_frame(vertices = NodeList, d= EdgeList, directed = FALSE))
它会发出我想要的图表。但是我需要能够使用邻接矩阵而不是 from 和 to 向量。函数graph_from_adjacency_matrix 不包含指定节点坐标的参数。如何做到这一点?
【问题讨论】:
-
使用graph_from_adjacency_matrix加载到图中,然后设置顶点属性;
vertex_attr -
... 但如果这仅用于绘图,那么您可以使用
layout参数;plot(g, layout=as.matrix(NodeList[-1])