2016-07-22 26 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

相关问题