1

I'm currently trying to plot images on my network graph in R. I'm relatively new to R, and am completely stuck trying to figure this out. Here's my syntax:

# 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)

I cannot figure it out. It is not throwing an error, but rather just plotting some stock image (a red node surrounded by yellow nodes) at every node. Any help would be greatly appreciated. Thanks!

  • 1
    great answer here which might be useful https://stackoverflow.com/questions/4975681/r-creating-graphs-where-the-nodes-are-images/4978111#4978111 , that answer ripped off here https://stackoverflow.com/questions/29189497/how-to-assign-different-images-to-different-vertices-in-an-igraph , and an alternate approach https://stackoverflow.com/questions/40120912/r-igraph-how-to-plot-vertices-with-mix-of-shapes-and-raster – user20650 Jul 10 '17 at 17:05
  • 1
    Thank you so much! That was all I needed. – Elliott Seiler Jul 10 '17 at 17:51

0 Answers0