试试ggiraph 包,它可以与ggraph 一起使用,您可以在示例here(页面底部)中看到。
供将来参考(如果上面的链接可能失效),这里是 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。