使用 plotly 或 Network 3D 将 igraph 转换为交互式绘图
Convert ggraph to interative plot with plotyly or Network3D
我正在寻找将 ggraph
对象转换为迭代力网络的示例或教程。
首先,我尝试使用 plotly::ggplotly
函数转换为 plotly
对象。但似乎 plotly
不能很好地处理这种转换并且错过了边缘。
但是我找到了network3D
,我可以将一个igraph
对象转换成一个network3D
对象,但这不是我想要的。而且这个包的功能太冗长了。无论如何,没有从ggraph
对象转换的函数。
所以,我的问题很基础,但是...您知道创建交互式 ggraph
网络的任何方法吗?
谢谢
尝试 ggiraph package, it works with ggraph as you can see in the example here(页面底部)。
为了以后参考(如果上面的link可能会死),这里是ggiraph的例子(不是我的代码):
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)))
plotly好像还不支持ggraph,不过你可以跟踪进度here。
我正在寻找将 ggraph
对象转换为迭代力网络的示例或教程。
首先,我尝试使用 plotly::ggplotly
函数转换为 plotly
对象。但似乎 plotly
不能很好地处理这种转换并且错过了边缘。
但是我找到了network3D
,我可以将一个igraph
对象转换成一个network3D
对象,但这不是我想要的。而且这个包的功能太冗长了。无论如何,没有从ggraph
对象转换的函数。
所以,我的问题很基础,但是...您知道创建交互式 ggraph
网络的任何方法吗?
谢谢
尝试 ggiraph package, it works with ggraph as you can see in the example here(页面底部)。
为了以后参考(如果上面的link可能会死),这里是ggiraph的例子(不是我的代码):
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)))
plotly好像还不支持ggraph,不过你可以跟踪进度here。