I would like to plot a graph with communities, in a similar way as igraph
do but using ggraph
.
Here is an example:
library(data.table)
library(ggplot2)
library(igraph)
actors <- data.table(name=c("Alice", "Bob", "Cecil", "David",
"Esmeralda","Denis","Adriana"),
age=c(48,33,45,34,21,35,36),
gender=c("F","M","F","M","F","M","F"))
actors[,a := 1:.N]
relations <- actors[actors,on = .(a > a)][,.(from = name,to = i.name)]
relations <- relations[!is.na(from)]
relations[c(1:3,12,8,7), weight := 10]
relations[!c(1:3,12,8,7), weight := 5]
relations[c(19:21),weight := 8]
I would like to have:
g <- graph_from_data_frame(relations, directed=F, vertices=actors )
eb <- cluster_fast_greedy(g,weights = E(g)$weight )
plot(eb,g)
But using ggraph
.
I know how to plot a simple graph:
ggraph(g, layout = 'kk') +
geom_edge_fan(aes(edge_width = weight),alpha = .3) +
geom_node_label(aes(label = name))+
theme_graph(foreground = 'steelblue', fg_text_colour = 'white')+
scale_edge_color_manual(values = c("grey50","grey80"))
and tried to use layout_with_fr(g,weights = E(g)$weight)
in the layout
argument of ggraph
, but without success.
How can I extract the layout of the igraph
plot to use it in ggraph
?