Before starting, make sure you have igraph installed and loaded.
#install.packages("igraph")
library(igraph)
##
## Attaching package: 'igraph'
##
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
##
## The following object is masked from 'package:base':
##
## union
from_nodes = c("Anna", "Bob", "Bob", "Charlie", "Charlie", "Denise", "Denise", "Fred")
to_nodes = c("Bob", "Charlie", "Denise", "Denise", "Fred", "Fred", "Evan", "Gina")
el_m = matrix(c(from_nodes, to_nodes), ncol = 2)
el_g = graph.edgelist(el_m, directed = FALSE)
This last line should give you the igraph object description:
el_g
## IGRAPH UN-- 7 8 --
## + attr: name (v/c)
## + edges (vertex names):
## [1] Anna --Bob Bob --Charlie Bob --Denise Charlie--Denise
## [5] Charlie--Fred Denise --Fred Denise --Evan Fred --Gina
The number of nodes (7) and edges (8) are displayed along with the UN for undirected named node network.
Finally, plot your graph (with a few plotting modifications added):
plot.igraph(el_g, vertex.size = 45, vertex.label.color = "red", vertex.color = "gray", edge.color = "black")
Learn more at:
?igraph.plotting