as_graph6 | R Documentation |
Generic function encoding undirected networks as 'graph6' symbol(s). See below for available methods.
as_graph6(object)
## S3 method for class 'matrix'
as_graph6(object)
## S3 method for class 'igraph'
as_graph6(object)
## S3 method for class 'network'
as_graph6(object)
## S3 method for class 'list'
as_graph6(object)
## Default S3 method:
as_graph6(object)
object |
a matrix, an igraph object or a network object or a list thereof. See Methods section below. |
The 'graph6' format is designed for undirected graphs. Error is thrown in case it is given a directed graph.
A character vector of 'graph6' symbols.
as_graph6(matrix)
: Expects object
to be a square matrix which is
interpreted as an adjacency matrix of an undirected graph. The function
reads only the upper triangle of the matrix and there is no test whether
the matrix is symmetric.
as_graph6(igraph)
: Igraph object
needs to be an undirected graph.
Requires igraph package.
as_graph6(network)
: Network object
needs to be a directed network.
Requires network package.
as_graph6(list)
: If object
is a list the function is applied to each
element. Consequently, it can be a list with a mixture of supported objects
classes (adjacency matrices, igraph, or network objects).
as_graph6(default)
: The default method throws an error about an unhandled
class.
# From adjacency matrix ----------------------------------------------------
am <- matrix(c(
0,1,1,
1,0,0,
1,0,0
), byrow=TRUE, ncol=3)
as_graph6(am)
# From igraph objects ------------------------------------------------------
if(requireNamespace("igraph", quietly=TRUE)) {
g <- igraph::graph_from_adjacency_matrix(am, mode = "undirected")
as_graph6(g)
}
# From network objects -----------------------------------------------------
if(requireNamespace("network", quietly=TRUE)) {
net <- network::network(am, directed=FALSE)
as_graph6(net)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.