我正在尝试使用以下代码通过图像的属性(类型)将其设置为顶点:
library(igraph)
library(png)
gi <- graph.formula(child -- org -- person)
img1 <- readPNG("baby-boy.png")
img2 <- readPNG("knife.png")
img3 <- readPNG("detective.png")
V(gi)$raster <- ni$type
V(gi)$raster <- gsub("child", "img1", V(gi)$raster)
V(gi)$raster <- gsub("org", "img2", V(gi)$raster)
V(gi)$raster <- gsub("person", "img3", V(gi)$raster)
plot(gi, layout_as_star(gi),
vertex.label.cex = 0.5,
edge.arrow.size = 0.1,
vertex.shape="raster",
vertex.size = 16,
vertex.size2 = 16)
结果是我收到以下错误消息:
"Error in rasterImage(ras, coords[i, 1] - size[i], coords[i, 2] - size2[i], :
invalid color name 'img1'"
,并且不绘制任何顶点。 我该如何解决这个问题?