View source: R/colorize_edge_attrs.R
colorize_edge_attrs | R Documentation |
Within a graph's internal edge data frame (edf), use a categorical edge attribute to generate a new edge attribute with color values.
colorize_edge_attrs(
graph,
edge_attr_from,
edge_attr_to,
cut_points = NULL,
palette = "Spectral",
alpha = NULL,
reverse_palette = FALSE,
default_color = "#D9D9D9"
)
graph |
A graph object of class |
edge_attr_from |
The name of the edge attribute column from which color values will be based. |
edge_attr_to |
The name of the new edge attribute to which the color values will be applied. |
cut_points |
An optional vector of numerical breaks for bucketizing continuous numerical values available in a edge attribute column. |
palette |
Can either be: (1) a palette name from the RColorBrewer
package (e.g., |
alpha |
An optional alpha transparency value to apply to the generated
colors. Should be in the range of |
reverse_palette |
An option to reverse the order of colors in the chosen
palette. The default is |
default_color |
A hexadecimal color value to use for instances when the
values do not fall into the bucket ranges specified in the |
A graph object of class dgr_graph
.
# Create a graph with 5
# nodes and 4 edges
graph <-
create_graph() %>%
add_path(n = 5) %>%
set_edge_attrs(
edge_attr = weight,
values = c(3.7, 6.3, 9.2, 1.6))
# We can bucketize values in
# the edge `weight` attribute using
# `cut_points` and, by doing so,
# 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_edge_attrs(
edge_attr_from = weight,
edge_attr_to = color,
cut_points = c(0, 2, 4, 6, 8, 10),
palette = "RdYlGn")
# Now there will be a `color`
# edge attribute with distinct
# colors (from the RColorBrewer
# Red-Yellow-Green palette)
graph %>% get_edge_df()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.