Within a graph's internal node data frame (ndf), copy the contents an existing node attribute and create a distinct node attribute within the ndf with a different attribute name.
copy_node_attrs(graph, node_attr_from, node_attr_to)
graph | a graph object of class
|
---|---|
node_attr_from | the name of the node attribute column from which values will be copied. |
node_attr_to | the name of the new node attribute column to which the copied values will be placed. |
a graph object of class
dgr_graph
.
# Create a random graph using the # `add_gnm_graph()` function graph <- create_graph() %>% add_gnm_graph( n = 5, m = 10, set_seed = 23) %>% set_node_attrs( node_attr = shape, values = "circle") %>% set_node_attrs( node_attr = value, values = rnorm( n = count_nodes(.), mean = 5, sd = 1) %>% round(1)) # Get the graph's internal # ndf to show which node # attributes are available graph %>% get_node_df()#> id type label shape value #> 1 1 <NA> 1 circle 5.3 #> 2 2 <NA> 2 circle 4.4 #> 3 3 <NA> 3 circle 5.8 #> 4 4 <NA> 4 circle 5.9 #> 5 5 <NA> 5 circle 6.2# Make a copy the `value` # node attribute as the # `width` node attribute graph <- graph %>% copy_node_attrs( node_attr_from = value, node_attr_to = size) # Get the graph's internal # ndf to show that the node # attribute had been copied graph %>% get_node_df()#> id type label shape value size #> 1 1 <NA> 1 circle 5.3 5.3 #> 2 2 <NA> 2 circle 4.4 4.4 #> 3 3 <NA> 3 circle 5.8 5.8 #> 4 4 <NA> 4 circle 5.9 5.9 #> 5 5 <NA> 5 circle 6.2 6.2