require(rviewgraph)
# First generate the random edges of an Erdos Renyi random graph.
f = sample(100,size=200,replace=TRUE)
t = sample(100,size=200,replace=TRUE)
# The following should all show the same graph:
# ... specified as a two column matrix.
v1 = rViewGraph(cbind(f,t))
# ... in 'igraph' preferred format.
v2 = rViewGraph(c(f,t))
# ... as an adjacency matrix.
x = matrix(0,ncol=max(f,t),nrow=max(f,t))
for (i in 1:length(f)) x[f[i],t[i]] = 1
v3 = rViewGraph(x)
# Specifying names, colours and shapes.
# Use unlabeled vertices, as red, green and blue diamonds.
v4 = rViewGraph(cbind(f,t), names = " ", cols = c(2,3,4), shapes=2)
# Use yellow vertices with random shapes, labeled with capital letters.
y = matrix(sample(1:26,100,TRUE),ncol=2)
v5 = rViewGraph(y,names=LETTERS,cols="cyan",shapes=sample(0:2,26,TRUE))
# Controlling a currently active GUI.
if (!is.null(v5))
{
# Shift the coordinates, although this is more
# easily done with mouse controls.
v5$setLayout(100 + v5$getLayout())
# Reset the coordinates to random values.
v5$setLayout()
# Pepare a plot for printing, fix it, and start a PostScript print job.
v5$hideAxes()
v5$showPaper("A3",F)
v5$stop()
v5$writePostScript()
}
Run the code above in your browser using DataLab