MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Case Studies: Network Analysis in R

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode