我正在尝试使用节点的坐标创建一个igraph图。我意识到通过R.的igraph包没有直接的方法来做到这一点。
有些方法可以使用layout()
函数在2D空间上绘制图形,但我需要从已知的节点坐标创建图形。我很感激任何人都可以提供的任何帮助。
为什么我试图以这种方式设置图表?在使用坐标参数化图形节点之后,我想使用概率测量来连接节点,该测量将节点之间的距离考虑在内。
感谢。 Hitaysh
# Initial Co-ordinates of nodes
n = 1000 # no. of nodes
nodes.coord <- data.frame(x=runif(n,min=0,max=n),
y=runif(n,min=0,max=n))
# Set up a graph with nodes on above co-ordinates...
P.S。这是我在StackOverflow上的第一篇文章。任何有关如何更好地提问的建设性反馈也是受欢迎的。
答案 0 :(得分:2)
经过多次阅读你的问题之后,我猜这样的事情会起作用
n = 20 # no. of nodes
set.seed(15)
nodes.coord <- data.frame(
x=runif(n,min=0,max=n),
y=runif(n,min=0,max=n)
)
gg <- graph.empty(n)
plot(gg, layout=as.matrix(nodes.coord[,c("x","y")]))
但是如果你要根据距离连接节点,那么在创建igraph对象之前找到连接可能是有意义的,因为你已经知道了位置。