View source: R/color_networks.R
color_networks | R Documentation |
color_networks()
takes as input a tibble graph (from tidygraph)
or a list of tibble graphs and associates a color for each graphs' edges and nodes,
depending on a chosen categorical variable in columnr_to_color
(most likely a cluster column).
color_alluvial()
takes a data.frame and associates a color to each value of the chosen
categorical variable in column_to_color
. This function may be used with any data.frame
even if it aims at coloring alluvial data frame created with
networks_to_alluv().
You may either provide the color palette, provide a data frame associating the different values of the categorical variable with colors, or let the function provide colors (see details).
color_networks( graphs, column_to_color, color = NULL, unique_color_across_list = FALSE ) color_alluvial(alluv_dt, column_to_color, color = NULL)
graphs |
A tibble graph from tidygraph or a list of tibble graphs. |
column_to_color |
The column of the categorical variable to use to color nodes and edges. For instance,
the |
color |
The colors to use. It may be a vector of colors (in a character format)
or a two columns data.frame with the first column as
the distinct observations of the |
unique_color_across_list |
If set to |
alluv_dt |
A data.frame of an alluvial created with networks_to_alluv() |
The best practice is to provide a list of colors equals to the number of categorical
variable to color. If you provide more colors, excess colors will not be used. If you
provide less colors, colors will be recycled. If you provide no colors, palette.colors()
of base R will be used: the 7 colors of ggplot2
palette will be used (black is excluded) and
then the 7 colors of Okabe-Ito
palette (black and gray are excluded). Above 14 colors,
the colors of the two palettes will be recycled.
The same tibble graph or list of tibble graphs as input, but with a new color
column for both nodes and edges.
library(networkflow) nodes <- Nodes_stagflation |> dplyr::rename(ID_Art = ItemID_Ref) |> dplyr::filter(Type == "Stagflation") references <- Ref_stagflation |> dplyr::rename(ID_Art = Citing_ItemID_Ref) temporal_networks <- build_dynamic_networks(nodes = nodes, directed_edges = references, source_id = "ID_Art", target_id = "ItemID_Ref", time_variable = "Year", cooccurrence_method = "coupling_similarity", time_window = 20, edges_threshold = 1, overlapping_window = TRUE, filter_components = TRUE, verbose = FALSE) temporal_networks <- add_clusters(temporal_networks, objective_function = "modularity", clustering_method = "leiden", verbose = FALSE) temporal_networks <- color_networks(graphs = temporal_networks, column_to_color = "cluster_leiden", color = NULL) temporal_networks[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.