坐标在igraph在R

问题描述:

我想要 1)获取网络的坐标 2)使用它们为其他网络始终具有相同的节点位置。坐标在igraph在R

当我得到节点的坐标并将坐标设置到我从中获得它们的同一个网络时,它会改变。 x位置保持不变,y位置与假想的y轴对称。因此,当应用两次时,该位置就是我想要的位置。

问题可能出在tkplot.getcoords()函数中。你知道是否有一个技巧来避免应用两次?

n <- 20 
mat <- matrix(1:n^2, n,n) 
g <- graph.adjacency(mat, mode="directed", weighted=TRUE, diag=FALSE) 
V(g)$color <- "white" 
id <- tkplot(g, edge.curved = 0.5) 

coor <- tkplot.getcoords(id,norm=F) 
coor 
tkplot.setcoords(id, coor) # wrong position 

coor <- tkplot.getcoords(id,norm=F) 
coor 
tkplot.setcoords(id, coor) # desired position 

你知道,如果有一个小窍门,以避免将它两次?

看起来好像你不得不翻转y坐标;这适用于我的电脑:

library(igraph) 
set.seed(1);n <- 5 
mat <- matrix(1:n^2, n,n) 
g <- graph.adjacency(mat, mode="directed", weighted=TRUE, diag=FALSE) 
V(g)$color <- "white" 
id <- tkplot(g, 200, 200, edge.curved = 0.5) 
coor <- tkplot.getcoords(id,norm=F) 
canvas_height <- as.numeric(tcltk::tkcget(tk_canvas(id), "-height"))-20 # twenty by trial&error - prly the frame border top&bottom? 
coor[,2] <- canvas_height-coor[,2] 
# move some vertices and... 
tkplot.setcoords(id, coor) # reset