【问题标题】:Issues with geographical coordinates with R tkplotR tkplot 的地理坐标问题
【发布时间】:2015-04-21 14:40:12
【问题描述】:

我想用地理坐标(epsg:27572)对图形的顶点进行空间化,但是当我使用tkplot 函数tkplot.setcoords() 时,坐标是“居中”的,出现一个 0,空间化是一种镜像对称真实的立场。一个例子:

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)

问题是coords 与初始相比已被转换:

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

很明显,坐标的第 2 列已“居中”为 0。tk 窗口的右下角出现一个节点。

【问题讨论】:

  • 也许你需要id &lt;- tkplot(g1, rescale = FALSE)
  • 如果# plot the spatialised graph coords &lt;- cbind(V(g1)$coordx, V(g1)$coordy) id &lt;- tkplot(g1, rescale = FALSE) tkplot.setcoords(id, coords) tkplot.center(id) tkplot.fit.to.screen(id)相同
  • 如果tkplot(g1, rescale = FALSE) 没有用处:'tk' 似乎适用于它自己的引用。最好的策略是使用igraph.to.gexf(g) 导出.gexf 以使用gephi 探索图形。
  • 好吧,tkplot(..., rescale = FALSE) 为我正确显示完整的图表.....

标签: r igraph tkplot


【解决方案1】:

也许尝试原始值:

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

然后像往常一样绘制

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 2020-11-04
    相关资源
    最近更新 更多