我目前正试图在R中的网络图上绘制图像。我对R来说相对较新,并且完全陷入困境,试图解决这个问题。这是我的语法:
# First, getting the appropriate libraries
library(igraph)
library(png)
library(raster)
library(rasterImage)
test.edges <- read.csv("TestEdges.csv", header = TRUE, stringsAsFactors = FALSE)
test.nodes <- read.csv("TestNodes.csv", header = TRUE, stringsAsFactors = FALSE)
img.D <- readPNG("./images/doctor.png")
img.L <- readPNG("./images/lab.png")
img.D <- as.raster(img.D)
img.L <- as.raster(img.L)
# Attempting to graph with images
graph.7 <- graph_from_data_frame(d = test.edges,directed = TRUE)
V(graph.7)$raster <- list(img.D, img.L)[V(graph.7)$type]
plot(graph.7, vertex.shape = "raster", vertex.label = NA, vertex.size = 16, vertex.size2 = 16, edge.width = 2)
我无法理解。它不是抛出错误,而只是在每个节点上绘制一些股票图像(黄色节点包围的红色节点)。任何帮助将不胜感激。谢谢!