2016-07-22 61 views
1

請看下面的例子扭曲:圖像使用它時,作爲IGRAPH節點

library(png) 
library(igraph) 

nodes=5 
mat = matrix(runif(n = nodes*nodes,min = 0,max = 10),nodes,nodes) 
mat.graph <- graph.adjacency(mat,weighted=TRUE,mode="undirected",diag=FALSE) 
imgfilename <- file.path(tempdir(), "img.png") 
imgfile <- download.file("https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Circle-icons-water.svg/2000px-Circle-icons-water.svg.png", 
        destfile=imgfilename,mode='wb') 
img <- readPNG(imgfilename) 
V(mat.graph)$raster <- list(img,img,img,img,img) 
plot(mat.graph ,vertex.size=E(mat.graph)$weight,edge.width=E(mat.graph)$weight, 
layout=layout.circle,vertex.shape="raster",vertex.label=NA,vertex.size=30, vertex.size2=30) 

我的問題是,繪製時被用作節點中的圖象被扭曲。是否可以保持寬度/長度比率是固定的?

此外,我看到節點的位置每次都隨着權值的變化而不斷變化。是否有可能讓節點也處於固定位置?

非常感謝您提前。

+0

順便說一句,如何組合與其他節點的形狀的光柵圖像對象? – pengchy

回答

1

它看起來像是覆蓋了第一個vertex.size包含它兩次。所以一個維度是固定的,而另一個維度取決於邊緣權重。相反,基於邊緣的權重設定兩個頂點尺寸:

plot(mat.graph, 
    vertex.size=4*E(mat.graph)$weight, 
    vertex.size2=4*E(mat.graph)$weight, 
    edge.width=E(mat.graph)$weight, 
    layout=layout.circle, 
    vertex.shape="raster", 
    vertex.label=NA) 

但是請注意,最高和最低的邊緣權重約16:1的比例,所以最小的頂點比最大的小一。

enter image description here

+0

多麼愚蠢的錯誤......感謝您發現它! – David

+0

Btw你知道爲什麼一些邊緣不能到達節點嗎? – David

+0

不確定。如果我想出解決方案,我會更新我的答案。 – eipi10

相關問題