# NOT RUN {
# Create a graph with 8 nodes and 7 edges
graph <-
  create_graph() %>%
  add_path(8) %>%
  set_node_attrs(
    "weight",
    c(8.2, 3.7, 6.3, 9.2,
      1.6, 2.5, 7.2, 5.4))
# Find group membership values for all nodes
# in the graph through the Walktrap community
# finding algorithm and join those group values
# to the graph's internal node data frame (ndf)
# with the `join_node_attrs()` function
graph <-
  graph %>%
  join_node_attrs(get_cmty_walktrap(.))
# Inspect the number of distinct communities
get_node_attrs(graph, "walktrap_group") %>%
  unique() %>%
  sort()
#> [1] 1 2 3
# Visually distinguish the nodes in the different
# communities by applying colors using the
# `colorize_node_attrs()` function; specifically,
# set different `fillcolor` values with an alpha
# value of 90 and apply opaque colors to the node
# border (with the `color` node attribute)
graph <-
  graph %>%
  colorize_node_attrs(
    "walktrap_group", "fillcolor", alpha = 90) %>%
  colorize_node_attrs(
    "walktrap_group", "color")
# Show the graph's internal node data frame
get_node_df(graph)
#>   id type label weight walktrap_group fillcolor   color
#> 1  1 <NA>     1    8.2              1 #FC8D5990 #FC8D59
#> 2  2 <NA>     2    3.7              1 #FC8D5990 #FC8D59
#> 3  3 <NA>     3    6.3              1 #FC8D5990 #FC8D59
#> 4  4 <NA>     4    9.2              3 #99D59490 #99D594
#> 5  5 <NA>     5    1.6              3 #99D59490 #99D594
#> 6  6 <NA>     6    2.5              2 #FFFFBF90 #FFFFBF
#> 7  7 <NA>     7    7.2              2 #FFFFBF90 #FFFFBF
#> 8  8 <NA>     8    5.4              2 #FFFFBF90 #FFFFBF
# Create a graph with 8 nodes and 7 edges
graph <-
  create_graph() %>%
  add_path(8) %>%
  set_node_attrs(
    "weight",
    c(8.2, 3.7, 6.3, 9.2,
      1.6, 2.5, 7.2, 5.4))
# We can bucketize values in `weight` using
# `cut_points` and assign colors to each of the
# bucketed ranges (for values not part of any
# bucket, a gray color is assigned by default)
graph <-
  graph %>%
  colorize_node_attrs(
    "weight", "fillcolor",
    cut_points = c(1, 3, 5, 7, 9))
# Now there will be a `fillcolor` node attribute
# with distinct colors (the `#D9D9D9` color is
# the default `gray85` color)
get_node_df(graph)
#>   id type label weight fillcolor
#> 1  1 <NA>     1    8.2   #2B83BA
#> 2  2 <NA>     2    3.7   #FDAE61
#> 3  3 <NA>     3    6.3   #ABDDA4
#> 4  4 <NA>     4    9.2   #D9D9D9
#> 5  5 <NA>     5    1.6   #D7191C
#> 6  6 <NA>     6    2.5   #D7191C
#> 7  7 <NA>     7    7.2   #2B83BA
#> 8  8 <NA>     8    5.4   #ABDDA4
# }
Run the code above in your browser using DataLab