Learn R Programming

DiagrammeR (version 0.7)

scale_nodes: Create numerical and color scales for node attributes

Description

Generates either numeric or color scales for specified node attributes and applies those scales to node data frames.

Usage

scale_nodes(nodes_df, to_scale, node_attr, range, scale_type = "linear")

Arguments

nodes_df
a data frame containing, at minimum, a column that contains node IDs for the graph. Optionally, additional columns (named as Graphviz node attributes) can be included with values for the named node attribute. These data frames can be conveniently generate
to_scale
a vector of numerical values serving as a basis for scaling; these currently need to be of the same length and order as the node IDs in the supplied node data frame, so, it's recommended that the value be a reference to a column of values residing in
node_attr
the name of the node attribute for which scaled values are to be created.
range
a vector of 2 elements providing either lower and upper numerical or X11 color values.
scale_type
the type of scaling to perform. Currently, linear is the only option available.

Value

  • a node data frame.

Examples

Run this code
# Add a node attribute which has values scaled to
# numeric data in another column
nodes <- create_nodes(nodes = 1:5,
                      label = FALSE,
                      type = "example",
                      data = sample(seq(1:20), 5))

nodes <- scale_nodes(nodes_df = nodes,
                     to_scale = nodes$data,
                     node_attr = "penwidth",
                     range = c(2, 5))

Run the code above in your browser using DataLab