问题
[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