## To display the graphs constructed the packages
## graph and Rgraphviz packages need to be loaded
library(graph)
library(Rgraphviz)
##
## Get some pairs
pairs <- matrix(c(1,2, 5,1, 3,4, 2,3, 4,2), ncol = 2, byrow = TRUE)
g <- graph_pairs(pairs)
## which can be displayed using plot(g)
plot(g)
## Build a graph from a list of paths
paths <- list(3:1, c(3,5,7), c(1,4,7), c(6,7))
gp <- graph_pairs(paths)
## graph package draws with grid, so clear
grid.newpage()
plot(gp)
## Nodes do not need to be numbers
alpha_paths <- list(letters[3:1], letters[c(3,5,7)],
letters[c(1,4,7)], letters[c(6,7)])
grid.newpage()
plot(graph_pairs(alpha_paths))
## Zenplots never uses this feature but you could
## build a directed graph with a single isolated node
dg <- graph_pairs(alpha_paths,
var.names = c(letters[1:7], "ALONE"),
edgemode = "directed" )
grid.newpage()
plot(dg)
Run the code above in your browser using DataLab