
Update module assignments from an existing column in graph object
Source:R/update_graph_modules.R
update_graph_modules2.RdUses the values of an existing node column as the new module assignment,
updating Modularity, modularity2, and modularity3
for seamless integration with ggNetView(). All other node columns
are preserved.
Arguments
- graph_obj
A graph object returned by
build_graph_*().- modules_new
Character. Name of an existing column in
graph_objnodes whose values define the new module assignment. The column may or may not contain"Others".- levels
Character vector. Optional explicit module order. If
NULL, order by module size (descending) and place"Others"at the end when present.
Value
A new graph object with updated Modularity, modularity2,
and modularity3 (and modularity if that column exists).
All other node columns are preserved.
Examples
data(ppi_example)
obj <- build_graph_from_df(
df = ppi_example$ppi,
node_annotation = ppi_example$annotation
)
# Re-assign modularity from the existing `group` node column.
obj2 <- update_graph_modules2(graph_obj = obj, modules_new = "group")
levels(get_graph_nodes(obj2)$Modularity)
#> [1] "D" "C" "B" "A"