1

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.

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. Thus, when applied twice, the position is the one that I want.

The problem is probably in the tkplot.getcoords() function. 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 

1 Answers1

0

Do you know if there is a trick to avoid applying it twice?

It seems as if you had to flip the y coordinates; 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
lukeA
  • 53,097
  • 5
  • 97
  • 100