0

I am trying to create something like this, but with different images for each node. PNG images as vertices in R (igraph)

I have tried using the same format but on a list of images, but I get this error:

Error in UseMethod("as.raster") : 
  no applicable method for 'as.raster' applied to an object of class "list"
img_train <- list.files(path = "~/Path/to/files", pattern = ".png")
img_list <- lapply(img_train, readPNG)

g <- graph.ring(5)
V(g)$raster <- replicate(vcount(g), img_list, simplify=FALSE)

plot(g, vertex.shape="raster", vertex.label=NA,
     vertex.size=1:10*5, vertex.size2=1:10*5)

I am not sure how raster works - so any help would be greatly appreciated. Thank you!

cms72
  • 177
  • 10
  • 2
    Don't you think it should be `list.files(path="~/Path/to/files", pattern=".png", full.names=TRUE)`? (This might be an artifact of the MWE here, but I want to make sure it wasn't a contributing cause.) If this is not the case, does `str(img_list)` look appropriate? – r2evans May 29 '19 at 05:48
  • 2
    I'm also wondering whether it should just be `V(g)$raster <- img_list`: you already have one image per node I'm assuming, so you don't need to repeat the image multiple times, and they're already in a list. – Marius May 29 '19 at 05:54
  • OMG. It worked! Thank you r2evans and Marius! – cms72 May 29 '19 at 06:39

0 Answers0