View source: R/add_nodes_attr.R
add_nodes_attr | R Documentation |
The function adds attributes to the nodes of a graph from
either an object of class data.frame
or from a shapefile layer.
The node IDs in the input objects must be the same as in the graph object.
add_nodes_attr( graph, input = "df", data, dir_path = NULL, layer = NULL, index = "Id", include = "all" )
graph |
A graph object of class |
input |
A character string indicating the nature of the input data from which come the attributes to add to the nodes.
In both cases, input attribute table or dataframe must have a column with the exact same values as the node IDs. |
data |
(only if 'input = "df"') The name of the object of
class |
dir_path |
(only if 'input = "shp"') The path (character string) to the directory containing the shapefile layer of type point whose attribute table contains the attributes to add to the nodes. |
layer |
(only if 'input = "shp"') The name (character string) of the shapefile layer of type point (without extension, ex.: "nodes" refers to "nodes.shp" layer) whose attribute table contains the attributes to add to the nodes. |
index |
The name (character string) of the column with the nodes names in the input data (column of the attribute table or of the dataframe). |
include |
A character string (vector) indicating which columns of the input data will be added as nodes' attributes. By default, 'include = "all"', i.e. every column of the input data is added. Alternatively, 'include' can be a vector with the names of the columns to add (ex.: "c('x', 'y', 'pop_name')"). |
The graph can be created with the function
graphab_to_igraph
by importing output from Graphab projects.
Values of the metrics computed at the node level with Graphab can then be
added to such a graph with this function.
A graph object of class igraph
P. Savary
data("data_tuto") graph <- data_tuto[[3]] df_nodes <- data.frame(Id = igraph::V(graph)$name, Area = runif(50, min = 10, max = 60)) graph <- add_nodes_attr(graph, data = df_nodes, input = "df", index = "Id", include = "Area")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.