Set the random number generator to make the experiments repeatable

set.seed(1234)

library(igraph)
source("http://michael.hahsler.net/SMU/ScientificCompR/code/map.R")

Create a random graph

g <-erdos.renyi.game(50, 3/50)
summary(g)
## IGRAPH U--- 50 93 -- Erdos renyi (gnp) graph
## attr: name (g/c), type (g/c), loops (g/l), p (g/n)

Plot graphs

plot(g)

plot of chunk unnamed-chunk-3

Plot with an externally created layout

layout <-layout.fruchterman.reingold(g)
plot(g, layout=layout)

plot of chunk unnamed-chunk-4

Interactive plot

tkplot(g)
## Loading required package: tcltk
## [1] 1

Inspect vertex degree and use the degree for vertex size

degree(g)
##  [1] 3 3 5 3 2 3 5 8 4 5 3 2 4 2 5 1 4 4 4 3 4 5 0 5 3 3 3 3 4 6 4 6 5 4 4
## [36] 3 4 6 5 6 3 2 4 2 6 2 4 4 1 2
hist(degree(g))

plot of chunk unnamed-chunk-6

plot(g, layout=layout, vertex.size=map(degree(g),c(1,20)))