The tbl_graph
class is a thin wrapper around an igraph
object that
provides methods for manipulating the graph using the tidy API. As it is just
a subclass of igraph
every igraph method will work as expected. A
grouped_tbl_graph
is the equivalent of a grouped_df
where either the
nodes or the edges has been grouped. The grouped_tbl_graph
is not
constructed directly but by using the group_by()
verb. After creation of a
tbl_graph
the nodes are activated by default. The context can be changed
using the activate()
verb and affects all subsequent operations. Changing
context automatically drops any grouping. The current active context can
always be extracted with as_tibble()
, which drops the graph structure and
just returns a tbl_df
or a grouped_df
depending on the state of the
tbl_graph
. The returned context can be overriden by using the active
argument in as_tibble()
.
# S3 method for data.frame
as_tbl_graph(x, directed = TRUE, ...)# S3 method for Node
as_tbl_graph(x, directed = TRUE, mode = "out", ...)
# S3 method for dendrogram
as_tbl_graph(x, directed = TRUE, mode = "out", ...)
# S3 method for graphNEL
as_tbl_graph(x, ...)
# S3 method for graphAM
as_tbl_graph(x, ...)
# S3 method for graphBAM
as_tbl_graph(x, ...)
# S3 method for hclust
as_tbl_graph(x, directed = TRUE, mode = "out", ...)
# S3 method for igraph
as_tbl_graph(x, ...)
# S3 method for list
as_tbl_graph(x, directed = TRUE, node_key = "name", ...)
# S3 method for matrix
as_tbl_graph(x, directed = TRUE, ...)
# S3 method for network
as_tbl_graph(x, ...)
# S3 method for phylo
as_tbl_graph(x, directed = NULL, ...)
# S3 method for evonet
as_tbl_graph(x, directed = TRUE, ...)
tbl_graph(nodes = NULL, edges = NULL, directed = TRUE, node_key = "name")
as_tbl_graph(x, ...)
# S3 method for default
as_tbl_graph(x, ...)
is.tbl_graph(x)
A tbl_graph
object
An object convertible to a tbl_graph
Should the constructed graph be directed (defaults to TRUE
)
Arguments passed on to the conversion function
In case directed = TRUE
should the edge direction be away from
node or towards. Possible values are "out"
(default) or "in"
.
The name of the column in nodes
that character represented
to
and from
columns should be matched against. If NA
the first column
is always chosen. This setting has no effect if to
and from
are given as
integers.
A data.frame
containing information about the nodes in the
graph. If edges$to
and/or edges$from
are characters then they will be
matched to the column named according to node_key
in nodes, if it exists.
If not, they will be matched to the first column.
A data.frame
containing information about the edges in the
graph. The terminal nodes of each edge must either be encoded in a to
and
from
column, or in the two first columns, as integers. These integers refer to
nodes
index.
as_tbl_graph(data.frame)
: Method for edge table and set membership table
as_tbl_graph(Node)
: Method to deal with Node objects from the data.tree package
as_tbl_graph(dendrogram)
: Method for dendrogram objects
as_tbl_graph(graphNEL)
: Method for handling graphNEL objects from the graph package (on Bioconductor)
as_tbl_graph(graphAM)
: Method for handling graphAM objects from the graph package (on Bioconductor)
as_tbl_graph(graphBAM)
: Method for handling graphBAM objects from the graph package (on Bioconductor)
as_tbl_graph(hclust)
: Method for hclust objects
as_tbl_graph(igraph)
: Method for igraph object. Simply subclasses the object into a tbl_graph
as_tbl_graph(list)
: Method for adjacency lists and lists of node and edge tables
as_tbl_graph(matrix)
: Method for edgelist, adjacency and incidence matrices
as_tbl_graph(network)
: Method to handle network objects from the network
package. Requires this packages to work.
as_tbl_graph(phylo)
: Method for handling phylo objects from the ape package
as_tbl_graph(evonet)
: Method for handling evonet objects from the ape package
as_tbl_graph(default)
: Default method. tries to call igraph::as.igraph()
on the input.
Constructors are provided for most data structures that resembles networks.
If a class provides an igraph::as.igraph()
method it is automatically
supported.
rstat_nodes <- data.frame(name = c("Hadley", "David", "Romain", "Julia"))
rstat_edges <- data.frame(from = c(1, 1, 1, 2, 3, 3, 4, 4, 4),
to = c(2, 3, 4, 1, 1, 2, 1, 2, 3))
tbl_graph(nodes = rstat_nodes, edges = rstat_edges)
Run the code above in your browser using DataLab