Question

[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?

Was it helpful?

Solution

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)

screenshot of plot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top