将其用作 Igraph 节点时图像失真
Image distorted when using it as Igraph node
考虑以下示例:
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)
我遇到的问题是用作节点的图像在绘制时会变形。是否可以保持 width/length 比率固定?
另外,我看到节点的位置每次都在变化,因为权重值也在变化。是否可以将节点也保持在固定位置?
非常感谢您。
您似乎通过包含两次来覆盖第一个 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,因此最小顶点比最大顶点 小 很多。
考虑以下示例:
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)
我遇到的问题是用作节点的图像在绘制时会变形。是否可以保持 width/length 比率固定?
另外,我看到节点的位置每次都在变化,因为权重值也在变化。是否可以将节点也保持在固定位置?
非常感谢您。
您似乎通过包含两次来覆盖第一个 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,因此最小顶点比最大顶点 小 很多。