I want to separate nodes given their attribute (a, b, c, d, e) such that attributes (a,b,c,d) are placed in the corners, while those with attribute d roam freely (are placed) by some algorithm.
Is that possible?
I know I can alter the placement from the layout functions like:
mylayout <- layout_with_kk(g)
and then modify the placement of some nodes, but then the others are not replaced, which might leave me with a “suboptimal” placement.
Test graph:
# some graph (similar to my problem)
a <- matrix(0,10,10)
for(i in 1:10){
a[i,] <- c(rep(0, 4),sample(c(0,1), 6, replace = T))
}
a[2,] <- c(rep(0, 4),sample(c(0,1), 6, replace = T))
a[3,] <- c(rep(0, 4),sample(c(0,1), 6, replace = T))
a[4,] <- c(rep(0, 4),sample(c(0,1), 6, replace = T))
colnames(a) <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
g <- igraph::graph_from_adjacency_matrix(a,
mode = "undirected",
add.colnames = NULL)
attribute <- c(rep("d", 6), "a", "b", "c", "d")
g <- igraph::set_vertex_attr(g, "attA", value = attribute)
# viz
GGally::ggnet2(g,
label = TRUE,
mode = layout_(g, as_tree(root = V(g)[1:4]))
)