Pairs are processed to produce a graph with the elements of the pairs as vertices and the pairs as undirected edges. The result can be displayed using plot().

graph_pairs(x, var.names = NULL, edgemode = c("undirected", "directed"))

Arguments

x

matrix or list of pairs along a zenpath. Can also be a list containing vectors representing paths in the graph. Every path must be of length at least 2 (i.e. each vector element of the list).

var.names

names of the variables appearing in x.

edgemode

type of edges to be used: either "undirected" (the default) or "directed" (in which case the order of the nodes in each pair matters).

Value

a graphNEL object; can be displayed using plot().

Note

zenplot() never use directed graphs nor graphs with isolated (disconnected) nodes.

See also

zenplot() which provides the zenplot.

Other tools related to constructing zenpaths: connect_pairs(), extract_pairs(), groupData(), indexData(), zenpath()

Author

Marius Hofert and Wayne Oldford

Examples

## To display the graphs constructed the packages
## graph and Rgraphviz packages need to be loaded
library(graph)
#> Loading required package: BiocGenerics
#> 
#> Attaching package: ‘BiocGenerics’
#> The following objects are masked from ‘package:stats’:
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from ‘package:base’:
#> 
#>     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
#>     as.data.frame, basename, cbind, colnames, dirname, do.call,
#>     duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
#>     lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
#>     pmin.int, rank, rbind, rownames, sapply, setdiff, sort, table,
#>     tapply, union, unique, unsplit, which.max, which.min
library(Rgraphviz)
#> Loading required package: grid
##
## 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)