Interactive plots with ggiraph
Up until now, we've been making static plots of our graphs. However, there are many features of our graph that we may want to visualize, and if we displayed them all at once, the image would be overwhelming. That's where interactive graphs can truly stand out. You can plot the basic graph structure and allow the user to see different vertex and edge properties based on how they interact with the plot. In this lesson we will build on work we've done with ggnetwork
. First, we'll take a 1% subsample of the bike sharing network (cut down for ease of visualization) and create a ggnetwork
plot. Then, we'll add betweenness centrality as a vertex property and create an interactive plot where centrality is displayed when the pointer hovers over a vertex.
This exercise is part of the course
Case Studies: Network Analysis in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# From previous step
static_network <- ggplot(
ggnetwork(trip_g_simp, arrow.gap = 0.01),
aes(x = x, y = y, xend = xend, yend = yend)
) +
geom_edges() +
geom_nodes(aes(size = cent)) +
theme_blank()
interactive_network <- static_network +
# Add an interactive point layer
___(
# Map tooltip and data_id to centrality
aes(tooltip = ___, data_id = ___)
)