ggnetwork
ggnetwork copied to clipboard
Interaction with ggiraph
Is there a way of adding interactivity such as nodes changing color or tooltip. I have made a limited tooltip to an example using ggiraph. Are there any other examples?
library(ggplot2)
library(rvg)
library(ggiraph)
library(network)
library(sna)
library(ggnetwork)
n <- network(rgraph(10, tprob = 0.2), directed = FALSE)
n %v% "family" <- sample(letters[1:3], 10, replace = TRUE)
n %v% "importance" <- sample(1:3, 10, replace = TRUE)
e <- network.edgecount(n)
set.edge.attribute(n, "type", sample(letters[24:26], e, replace = TRUE))
set.edge.attribute(n, "day", sample(1:3, e, replace = TRUE))
df<-ggnetwork(n, layout = "fruchtermanreingold", cell.jitter = 0.75)
#df$tooltip <- paste0("Node ID = ", df$vertex.names)
df$tooltip <- paste0("Betweenness = ", round(betweenness(n)[df$vertex.names],2))
gg_point_1 <- ggplot(df, aes(x = x, y = y, xend=xend, color=family, yend=yend, tooltip = tooltip) ) +
geom_edges(aes(linetype = type), color = "grey50") +
geom_nodes(color = "black", size = 8) +
theme_blank() +
geom_nodetext(aes(label = LETTERS[vertex.names]), fontface = "bold") +
geom_point_interactive(size=5)
# htmlwidget call
ggiraph(code = {print(gg_point_1)}, width = 7, height = 6, hover_css = "{fill:orange;r:6px;}")
Thanks for that question. I bookmarked ggiraph some time ago, but am not too much into interactive widgets and did not explore interactivity with ggnetwork.
The vignettes of ggiraph suggest that there are ways to make changes to the hovered part of the widget, as well as to the tooltip.
I will take a further look and add a vignette to the package if I find something interesting.
P.S. @jalapic just found your interactive network viz slides, very impressive job!
Thanks - love the package- thank you