links_nodes_from_mat {foodingraph} | R Documentation |
Extracts links and nodes
Description
From an adjacency matrix, extracts two data.frames/tibbles
Links. columns : from, to, with, weight
Nodes. columns : name, title. name corresponds to the names used in 'from' and 'to'
Usage
links_nodes_from_mat(adjacency_matrix, legend, threshold = 0,
abs_threshold = TRUE, filter_nodes = TRUE)
Arguments
adjacency_matrix |
: a matrix of size n x n, each element being a number explaining the relationship e.g. coefficient, information between two variables given in the column and row names /!\ As this code is to draw undirected graphs, only the lower triangular part of adjacency matrix is used to extract the information. |
legend |
: a data frame of columns in order : 1) name, str : name of the node in the adjacency matrix, e.g. CRUDSAL_cat 2) title, str : name of the node, e.g. Raw vegetables 3) family, factor : (optional) the family the node belongs to, e.g. Vegetables |
threshold |
numeric) : a number defining the minimal threshold. If the weights are less than this threshold, they will be set to 0. |
abs_threshold |
(bool) : should the threshold keep negative values,
e.g. if |
filter_nodes |
(bool) : should the variables not in the adjacency
matrix be displayed on the graph? Default is TRUE
CAREFUL : if set to |
Value
A list of two data frames : links and nodes.
Examples
adj_matrix <- cor(iris[,-5])
legend <- data.frame(name = colnames(iris[,-5]),
title = colnames(iris[,-5]))
links_nodes_from_mat(adj_matrix, legend)