ggnetwork icon indicating copy to clipboard operation
ggnetwork copied to clipboard

Interaction with ggiraph

Open jalapic opened this issue 9 years ago • 3 comments
trafficstars

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;}") 

jalapic avatar Apr 03 '16 13:04 jalapic

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.

briatte avatar Apr 03 '16 17:04 briatte

P.S. @jalapic just found your interactive network viz slides, very impressive job!

briatte avatar Apr 19 '16 20:04 briatte

Thanks - love the package- thank you

jalapic avatar Apr 19 '16 22:04 jalapic