Graphics Reference
In-Depth Information
trolled layout, but it can be a bit challenging to install. Rgraphviz is available through the Biocon-
ductor repository system.
Using Text Labels in a Network Graph
Problem
You want to use text labels in a network graph.
Solution
The vertices/nodes may have names, but these names are not used as labels by default. To set
library(igraph)
library(gcookbook)
# For the data set
# Copy madmen and drop every other row
m
<-
madmen[
1
:nrow(madmen)
%%
2
==
1
, ]
g
<-
graph.data.frame(m, directed
=
FALSE
FALSE
)
# Print out the names of each vertex
V(g)$name
[
1
]
"Betty Draper"
"Don Draper"
"Harry Crane"
"Joan Holloway"
[
5
]
"Lane Pryce"
"Peggy Olson"
"Pete Campbell"
"Roger Sterling"
[
9
]
"Sal Romano"
"Henry Francis"
"Allison"
"Candace"
[
13
]
"Faye Miller"
"Megan Calvet"
"Rachel Menken"
"Suzanne Farrell"
[
17
]
"Hildy"
"Franklin"
"Rebecca Pryce"
"Abe Drexler"
[
21
]
"Duck Phillips"
"Playtex bra model" "Ida Blankenship"
"Mirabelle Ames"
[
25
]
"Vicky"
"Kitty Romano"
plot(g, layout
=
layout.fruchterman.reingold,
vertex.size
=
4
,
# Smaller nodes
vertex.label
=
V(g)$name,
# Set the labels
vertex.label.cex
=
0.8
,
# Slightly smaller font
vertex.label.dist
=
0.4
,
# Offset the labels
vertex.label.color
=
"black"
)