Plot image as a point in network graph using ggplot2 in R

Viewed 55

I want to use a dolphin image as the shape of nodes in my network graph using ggplot2. I already read the image; however, I cannot convert it into the type of shape to use it in geom_nodes. Can anyone know how to plot the image as a point in my code, please?

library("ggimage")
library('png')
img.1 <- readPNG("dolphin.png")

                
library(network)
nodes <- read.csv(file='dolphin_nodes.csv')
nodes
edges <- read.csv(file='dolphin_edges.csv')
edges
net <- network(x=edges, vertices=nodes, directed = FALSE)
net
library(ggnetwork)
n <- ggnetwork(net)
library(ggplot2)
network <- ggplot(n, aes(x=x,y=y,
                         xend=xend, yend=yend, )) + theme_void() +
          geom_nodes(aes(size=group, color = group), shape = "square") +
          geom_edges(color = "grey70") +
  geom_edgetext(aes(label = group), color = "white", fill = "grey25") +
  theme_minimal() +
  theme(axis.text = element_blank(),
        axis.title = element_blank(),
        panel.background = element_rect(fill = "grey25"),
        panel.grid = element_blank()) 
network

dolphin

graph

0 Answers
Related