簡體   English   中英

R中的igraph中的坐標

[英]Coordinates in igraph in R

我試圖1)獲取網絡的坐標2)使用它們為其他網絡始終具有相同的節點位置。

當我得到節點的坐標並將坐標設置為我從中得到它們的同一網絡時,它會發生變化。 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM