With a graph object of class
dgr_graph
, add a node prism to the graph.
add_prism(graph, n, type = NULL, label = TRUE, rel = NULL, node_aes = NULL, edge_aes = NULL, node_data = NULL, edge_data = NULL)
graph | a graph object of class
|
---|---|
n | the number of nodes describing the shape
of the prism. For example, the triagonal prism has
|
type | an optional string that describes the entity type for the nodes to be added. |
label | either a vector object of length
|
rel | an optional string for providing a relationship label to all new edges created in the node prism. |
node_aes | an optional list of named vectors
comprising node aesthetic attributes. The helper
function |
edge_aes | an optional list of named vectors
comprising edge aesthetic attributes. The helper
function |
node_data | an optional list of named vectors
comprising node data attributes. The helper
function |
edge_data | an optional list of named vectors
comprising edge data attributes. The helper
function |
a graph object of class dgr_graph
.
# Create a new graph and # add 2 prisms graph <- create_graph() %>% add_prism( n = 3, type = "prism", label = "a") %>% add_prism( n = 3, type = "prism", label = "b") # Get node information from this graph graph %>% get_node_info()#> id type label deg indeg outdeg loops #> 1 1 prism a 3 1 2 0 #> 2 2 prism a 3 1 2 0 #> 3 3 prism a 3 1 2 0 #> 4 4 prism a 3 2 1 0 #> 5 5 prism a 3 2 1 0 #> 6 6 prism a 3 2 1 0 #> 7 7 prism b 3 1 2 0 #> 8 8 prism b 3 1 2 0 #> 9 9 prism b 3 1 2 0 #> 10 10 prism b 3 2 1 0 #> 11 11 prism b 3 2 1 0 #> 12 12 prism b 3 2 1 0# Node and edge aesthetic and data # attributes can be specified in # the `node_aes`, `edge_aes`, # `node_data`, and `edge_data` # arguments set.seed(23) graph_w_attrs <- create_graph() %>% add_prism( n = 3, label = c( "one", "two", "three", "four", "five", "six"), type = c( "a", "a", "b", "b", "c", "c"), rel = "A", node_aes = node_aes( fillcolor = "steelblue"), edge_aes = edge_aes( color = "red", penwidth = 1.2), node_data = node_data( value = c( 1.6, 2.8, 3.4, 3.2, 5.3, 6.2)), edge_data = edge_data( value = rnorm( n = 9, mean = 5.0, sd = 1.0))) # Get the graph's node data frame graph_w_attrs %>% get_node_df()#> id type label fillcolor value #> 1 1 a one steelblue 1.6 #> 2 2 a two steelblue 2.8 #> 3 3 b three steelblue 3.4 #> 4 4 b four steelblue 3.2 #> 5 5 c five steelblue 5.3 #> 6 6 c six steelblue 6.2#> id from to rel penwidth color value #> 1 1 1 2 A 1.2 red 5.996605 #> 2 2 2 3 A 1.2 red 6.107490 #> 3 3 3 1 A 1.2 red 4.721914 #> 4 4 4 5 A 1.2 red 6.019205 #> 5 5 5 6 A 1.2 red 5.045437 #> 6 6 6 4 A 1.2 red 6.575780 #> 7 7 1 4 A 1.2 red 5.218288 #> 8 8 2 5 A 1.2 red 3.953465 #> 9 9 3 6 A 1.2 red 4.711311