Learn R Programming

DiagrammeR (version 0.8.2)

edge_count: Get count of all edges or edges with distinct relationship types

Description

From a graph object of class dgr_graph, get a count of edges in the graph and optionally obtain a count of edges by their relationship type.

Usage

edge_count(graph, rel = FALSE)

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
rel
either a logical value, where TRUE provides a named vector of edge count by type and FALSE (the default) provides a total count of edges, or, a string corresponding to one or more edge relationship types.

Value

a numeric vector of single length.

Examples

Run this code
## Not run: 
# # Before getting counts of edges, create a simple graph
# nodes <-
#   create_nodes(nodes = LETTERS,
#                label = TRUE,
#                type = c(rep("a_to_g", 7),
#                         rep("h_to_p", 9),
#                         rep("q_to_x", 8),
#                         rep("y_and_z", 2)))
# 
# edges <-
#   create_edges(from = sample(LETTERS, replace = TRUE),
#                to = sample(LETTERS, replace = TRUE),
#                rel = c(rep("rel_a", 7),
#                        rep("rel_b", 9),
#                        rep("rel_c", 8),
#                        rep("rel_d", 2)))
# 
# graph <-
#   create_graph(nodes_df = nodes,
#                edges_df = edges,
#                graph_attrs = "layout = neato",
#                node_attrs = c("fontname = Helvetica",
#                               "shape = circle"))
# 
# # Get a total count of edges with no grouping
# edge_count(graph, rel = FALSE)
# #> [1] 26
# 
# # Get a count of edge of one or more specified rels
# edge_count(graph, rel = "rel_a")
# #> [1] 7
# 
# edge_count(graph, rel = c("rel_a", "rel_b"))
# #> [1] 16
# ## End(Not run)

Run the code above in your browser using DataLab