PNG images as vertices in R (igraph) [duplicate]

泄露秘密 提交于 2019-12-11 07:14:38

问题


[R help]

Hello, is there any way to use png images as vertices in R? Specifically while still using the igraph package?

For example I have some PNG images 1.png 2.png 3.png

Can I replace certain vertices with 1.png, others with 2.png, and the rest with 3.png?


回答1:


This is simple with the new raster vertex shape:

library(png)
library(igraph)

# To get an image to plot
imgfilename <- file.path(tempdir(), "igraph2.png")
imgfile <- download.file("http://igraph.sourceforge.net/images/igraph2.png",
                         destfile=imgfilename)
img <- readPNG(imgfilename)

g <- graph.ring(10)
# This is a complex attribute, so supply a list here
V(g)$raster <- replicate(vcount(g), img, simplify=FALSE)
plot(g, vertex.shape="raster", vertex.label=NA,
     vertex.size=1:10*5, vertex.size2=1:10*5)



来源:https://stackoverflow.com/questions/21423854/png-images-as-vertices-in-r-igraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!