I was looking for an example or tutorial to convert a ggraph
object to an iterative force network.
First I tried to convert to plotly
object using plotly::ggplotly
function. But seems the plotly
don't deal nicely with this kind of conversion and miss the edges.
But I find the network3D
, I can convert an igraph
object to a network3D
object, but it is not what I wanted. And this package has too verbose functions. Anyway, there is no function to convert from ggraph
object.
So, my question is really basic but... Do you know any method to crate an interactive ggraph
network?
Thanks
Try the ggiraph package, it works with ggraph as you can see in the example here (bottom of the page).
For future reference (if the above link may die), here's the example of ggiraph (not my code):
library(ggraph)
library(igraph)
library(ggiraph)
actors <- data.frame(
name = c("Alice", "Bob", "Cecil", "David", "Esmeralda"),
age = c(48,33,45,34,21),
gender = c("F","M","F","M","F")
)
relations <- data.frame(
from = c("Bob", "Cecil", "Cecil", "David", "David", "Esmeralda"),
to = c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
same.dept = c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),
friendship = c(4,5,5,2,1,1),
advice = c(4,5,5,4,2,3)
)
g <- graph_from_data_frame(relations,
directed = TRUE, vertices = actors)
z <- ggraph(g, layout = 'linear', circular = TRUE) +
geom_edge_arc(color = "red", edge_width = .2) +
geom_point_interactive(size = 5,
mapping = aes(x = x, y = y, data_id = gender,
tooltip = paste0(name, ": ", age, "y.o."))
) + theme_graph()
girafe(ggobj = z, width_svg = 5, height_svg = 5,
options = list(opts_sizing(rescale = FALSE)))
It seems plotly does not support ggraph yet, but you can track the progress here.