Interactive javascript plots
Another widely used framework for creating interactive plots is D3.js. It has a specific standard for creating network plots that we can automatically generate in R. On the one hand, this is highly convenient because, with just a few lines of code, you'll be able to create fully interactive D3.js plots. The drawback is that real customization only comes when you directly edit the output javascript source code from R (which is beyond the scope of this course). Nonetheless, it is quick and easy to create a nice D3.js network plot in R using the d3network library. In this lesson we'll load up the #rstats Twitter dataset and add community membership. Then we'll create a subgraph of just a few communities and render a D3.js network graph.
The tweet graph object, retweet_samp, is available.
Diese Übung ist Teil des Kurses
Case Studies: Network Analysis in R
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Run this to see the static version of the plot
ggplot(ggnetwork(retweet_samp, arrow.gap = 0.01),
aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(color = "black") +
geom_nodes(aes(color = as.factor(comm))) +
theme_blank()
# Convert retweet_samp to a networkD3 object
nd3 <-igraph_to_networkD3(___, V(___)$___)
# View the data structure
str(nd3)