graphlayouts
graphlayouts copied to clipboard
Group-in-a-box layout
Hi David, Is there a plan to add a Group-in-a-box layout function,
Reference link:
http://www.cs.umd.edu/hcil/trs/2011-24/2011-24.pdf
https://bl.ocks.org/rpgove/386b7a28977a179717a460f9a541af2a
Thank you for creating this perfect package!
Thanks for the suggestion. Looks interesting and I will put it on the agenda. Something similar is already possible with some hacking (see below).
library(igraph)
library(ggraph)
library(graphlayouts)
data <- jsonlite::fromJSON("https://bl.ocks.org/rpgove/raw/386b7a28977a179717a460f9a541af2a/c0c01cbfe9618e6ae1d98627da4ee03e3d8c0b23/jean.json")
nodes <- data.frame(name = data$nodes$id,full_name=data$nodes$name,grp=data$nodes$community)
links <- data.frame(source=data$links$source,target=data$links$target)
g <- graph_from_data_frame(links,FALSE,nodes)
el <- as_edgelist(g,names=FALSE)
g1 <- delete.edges(g,which(V(g)$grp[el[,1]] != V(g)$grp[el[,2]]))
xy <- layout_with_stress(g1,bbox=10)
ggraph(g,"manual",x=xy[,1],y=xy[,2])+
geom_edge_link0(edge_color="grey66")+
geom_node_point(shape=21,size=5,aes(fill=as.factor(grp)),show.legend = FALSE)+
ggforce::geom_mark_rect(
aes(x, y, group = as.factor(grp)),radius = unit(0, "mm"),
expand = unit(5, "mm"),
alpha = 0.25,show.legend = FALSE
)
Created on 2021-12-07 by the reprex package (v2.0.1)