0

I want to spatialise graph's vertex with geographical coordinates (epsg:27572) but when I use the tkplot function tkplot.setcoords(), coordinates are 'centred', one 0 appears and the spatialisation is a kind of mirror symmetry of the true positions. An example:

library(igraph)
library(tcltk)

relations <- read.table(header=TRUE, check.names= FALSE, textConnection("
  A B      x       y
1 1 2 762920 1872674
2 2 3 778202 1899896
3 3 5 746324 1859111
4 4 5 762920 1872674
5 5 6 762920 1872674
6 6 3 762920 1872674"))

g1 <- graph.data.frame(relations, directed=TRUE)

# fill vertex attributes with coordinates of the table 'relations'
for(i in 1:length(V(g1))){
  for(j in 1:nrow(relations)){
    if(V(g1)[i]$name==as.character(relations$A[j])){
      V(g1)[i]$coordx <- relations$x[j]
      V(g1)[i]$coordy <- relations$y[j]
    }
  }
}
list.vertex.attributes(g1)

# plot the spatialised graph
coords <- cbind(V(g1)$coordx, V(g1)$coordy)
id <- tkplot(g1)
tkplot.setcoords(id, coords)
tkplot.center(id)
tkplot.fit.to.screen(id)

Problem is that coords were tranformed compared to initial:

> tkplot.getcoords(id)
       [,1]  [,2]
[1,] 762920 27222
[2,] 778202     0
[3,] 746324 40785
[4,] 762920 27222
[5,] 762920 27222
[6,] 762920 27222

Obviously the 2nd column of the coordinates has been 'centred' to 0. A node appears in the right bottom of tk window.

  • Maybe you jsut need `id <- tkplot(g1, rescale = FALSE)` ? – Gabor Csardi Apr 21 '15 at 15:26
  • if `# plot the spatialised graph coords <- cbind(V(g1)$coordx, V(g1)$coordy) id <- tkplot(g1, rescale = FALSE) tkplot.setcoords(id, coords) tkplot.center(id) tkplot.fit.to.screen(id)` same – user23453 Apr 24 '15 at 19:51
  • if `tkplot(g1, rescale = FALSE)` won't be usefull: 'tk' seems to work with its own references. Best strategy will be to export in **.gexf** with `igraph.to.gexf(g)` to explore graph with [gephi](http://gephi.github.io/). – user23453 Apr 24 '15 at 19:59
  • Well, `tkplot(..., rescale = FALSE)` show the full graph properly for me..... – Gabor Csardi Apr 24 '15 at 21:27

1 Answers1

0

Maybe try the original values:

coords <- cbind(relations$x, relations$y)

and then plot as usual

id <- tkplot(g1)
tkplot.setcoords(id, coords)
tkplot.center(id)
tkplot.fit.to.screen(id)