# NOT RUN {
# Create a random graph
graph <-
create_random_graph(
n = 5, m = 5,
set_seed = 23)
# For node ID values of `1` to `3`, choose
# to display the node `value` attribute (for
# the other nodes, display nothing)
graph <-
graph %>%
set_node_attr_to_display(
nodes = 1:3,
attr = value,
default = NA)
# Show the graph's node data frame; the
# `display` node attribute will show for
# each row, which node attribute value to
# display when the graph is rendered
get_node_df(graph)
#> id type label display value
#> 1 1 <NA> 1 value 6.0
#> 2 2 <NA> 2 value 2.5
#> 3 3 <NA> 3 value 3.5
#> 4 4 <NA> 4 <NA> 7.5
#> 5 5 <NA> 5 <NA> 8.5
# This function can be called multiple
# times on a graph; after the first time
# (i.e., creation of the `display`
# attribute), the `default` value won't
# be used
graph %>%
set_node_attr_to_display(
nodes = 4,
attr = label) %>%
set_node_attr_to_display(
nodes = c(1, 5),
attr = id) %>%
get_node_df()
#> id type label display value
#> 1 1 <NA> 1 id 6.0
#> 2 2 <NA> 2 value 2.5
#> 3 3 <NA> 3 value 3.5
#> 4 4 <NA> 4 label 7.5
#> 5 5 <NA> 5 id 8.5
# }
Run the code above in your browser using DataLab