briatte / briatte/ggnetwork

Interaction with ggiraph

Open
#6 3 comments 1 reaction 1 assignee Claimed by @briatte View on GitHub
question
Dominant language
HTML
Stars
154
Forks
29
PR merge metrics
No merged PRs in 30d

Description

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?

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.