rename_node_attrs {DiagrammeR} | R Documentation

## Rename a node attribute

### Description

Within a graph's internal node data frame (ndf), rename an existing node attribute.

### Usage

    rename_node_attrs(graph, node_attr_from, node_attr_to)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`node_attr_from` | the name of the node attribute that will be renamed.
`node_attr_to` | the new name of the node attribute column identified in `node_attr_from`.

### Value

a graph object of class `dgr_graph`.

### Examples

    # Create a random graph
    graph <-
      create_random_graph(
        n = 5, m = 10,
        set_seed = 23) %>%
      set_node_attrs(
        node_attr = shape,
        values = "circle")

    # Get the graph's internal ndf
    # to show which node attributes
    # are available
    get_node_df(graph)
    #>   id type label value  shape
    #> 1  1 <NA>     1   6.0 circle
    #> 2  2 <NA>     2   2.5 circle
    #> 3  3 <NA>     3   3.5 circle
    #> 4  4 <NA>     4   7.5 circle
    #> 5  5 <NA>     5   8.5 circle

    # Rename the `value` node
    # attribute as `weight`
    graph <-
      graph %>%
      rename_node_attrs(
        node_attr_from = value,
        node_attr_to = weight)

    # Get the graph's internal
    # ndf to show that the node
    # attribute had been renamed
    get_node_df(graph)
    #>   id type label weight  shape
    #> 1  1 <NA>     1    6.0 circle
    #> 2  2 <NA>     2    2.5 circle
    #> 3  3 <NA>     3    3.5 circle
    #> 4  4 <NA>     4    7.5 circle
    #> 5  5 <NA>     5    8.5 circle

[Package DiagrammeR version 0.9.2 Index]