将其用作Igraph节点时图像会发生扭曲

将其用作Igraph节点时图像会发生扭曲,r,plot,igraph,R,Plot,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

考虑以下示例:

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)
库(png)
图书馆(igraph)
节点数=5
mat=矩阵(runif(n=节点*节点,最小值=0,最大值=10),节点,节点)

mat.graph看起来您通过两次包含它来覆盖第一个
顶点.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,因此最小顶点比最大顶点小得多


顺便问一句,您知道为什么某些边无法到达节点吗?不确定。如果我找到一个解决方案,我会更新我的答案。顺便问一下,如何将光栅图像对象与其他节点形状混合?