Learn R Programming

DiagrammeR (version 1.0.10)

set_node_attrs: Set node attribute values

Description

From a graph object of class dgr_graph, set node attribute values for one or more nodes.

Usage

set_node_attrs(graph, node_attr, values, nodes = NULL)

Value

A graph object of class dgr_graph.

Arguments

graph

A graph object of class dgr_graph.

node_attr

The name of the attribute to set.

values

The values to be set for the chosen attribute for the chosen nodes.

nodes

An optional vector of node IDs for filtering the list of nodes present in the graph.

See Also

Other Node creation and removal: add_n_node_clones(), add_n_nodes_ws(), add_n_nodes(), add_node_clones_ws(), add_node_df(), add_nodes_from_df_cols(), add_nodes_from_table(), add_node(), colorize_node_attrs(), copy_node_attrs(), create_node_df(), delete_nodes_ws(), delete_node(), drop_node_attrs(), join_node_attrs(), layout_nodes_w_string(), mutate_node_attrs_ws(), mutate_node_attrs(), node_data(), recode_node_attrs(), rename_node_attrs(), rescale_node_attrs(), set_node_attr_to_display(), set_node_attr_w_fcn(), set_node_attrs_ws(), set_node_position()

Examples

Run this code
# Create a node data frame (ndf)
ndf <-
  create_node_df(
    n = 4,
    type = "basic",
    label = TRUE,
    value = c(3.5, 2.6, 9.4, 2.7))

# Create an edge data frame (edf)
edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = "leading_to")

# Create a graph
graph <-
  create_graph(
    nodes_df = ndf,
    edges_df = edf)

# Set attribute `color = "green"` for
# nodes `1` and `3` using the graph object
graph <-
  graph %>%
  set_node_attrs(
    node_attr = color,
    values = "green",
    nodes = c(1, 3))

# View the graph's node data frame
graph %>% get_node_df()

# Set attribute `color = "blue"` for
# all nodes in the graph
graph <-
  graph %>%
  set_node_attrs(
    node_attr = color,
    values = "blue")

# Display the graph's ndf
graph %>% get_node_df()

Run the code above in your browser using DataLab