简体   繁体   English

R中的igraph中的坐标

[英]Coordinates in igraph in R

I am trying to 1) get the coordinates of a network 2) use them for other networks to have always the same position of nodes. 我试图1)获取网络的坐标2)使用它们为其他网络始终具有相同的节点位置。

When I get the coordinates of the nodes and set the coordinates to the same network from which I got them, it changes. 当我得到节点的坐标并将坐标设置为我从中得到它们的同一网络时,它会发生变化。 The x position remains the same and the y position becomes symmetric to the hypothetical y axes. x位置保持不变,y位置与假想的y轴对称。 Thus, when applied twice, the position is the one that I want. 因此,当应用两次时,位置是我想要的位置。

The problem is probably in the tkplot.getcoords() function. 问题可能出在tkplot.getcoords()函数中。 Do you know if there is a trick to avoid applying it twice? 你知道是否有一个技巧可以避免两次使用它?

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 

Do you know if there is a trick to avoid applying it twice? 你知道是否有一个技巧可以避免两次使用它?

It seems as if you had to flip the y coordinates; 好像你不得不翻转y坐标; this works on my computer: 这适用于我的电脑:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM