DiagrammeR (version 0.9.2)

add_global_graph_attrs: Add one or more global graph attributes

Description

Add global attributes of a specific type (either graph_attrs, node_attrs, or edge_attrs for a graph object of class dgr_graph).

Usage

add_global_graph_attrs(graph, attr, value, attr_type)

Arguments

graph

a graph object of class dgr_graph.

attr

the name of the attribute to set for the type of global attribute specified.

value

the value to be set for the chosen attribute specified in the attr_for_type argument.

attr_type

the specific type of global graph attribute to set. The type is specified with graph, node, or edge.

Value

a graph object of class dgr_graph.

Examples

Run this code
# NOT RUN {
# Create a new graph and set some global attributes
graph <-
  create_graph() %>%
  set_global_graph_attrs(
    attr = "overlap",
    value = "true",
    attr_type = "graph")

# Verify that the global attributes have been set
get_global_graph_attrs(graph)
#>      attr value attr_type
#> 1 overlap  true     graph

# Add to this set with by using the
# `add_global_graph_attrs()` function and then
# view the collection of attributes
graph <-
  graph %>%
  add_global_graph_attrs(
    attr = "penwidth",
    value = 12,
    attr_type = "node")

get_global_graph_attrs(graph)
#>       attr value attr_type
#> 1  overlap  true     graph
#> 2 penwidth    12      node

# When adding an attribute where `attr`
# and `attr_type` exists, the value provided
# will serve as an update
graph %>%
  add_global_graph_attrs(
    attr = "penwidth",
    value = 15,
    attr_type = "node") %>%
  get_global_graph_attrs()
#>       attr value attr_type
#> 1  overlap  true     graph
#> 2 penwidth    15      node
# }

Run the code above in your browser using DataCamp Workspace