Recipe 7 Visualizing a Graph of Retweet Relationships

7.1 Problem

You want to visualize a graph of retweets.

7.2 Solution

There are a plethora of ways to visualize graph structures in R. One recent and popular one is ggraph.

Given the cookbook-nature of this book, we’ll cover one more visualization about retweet relationships. Let’s explore the entire retweet network and label the screen names with the most retweets over a given search term (and use #rstats again, but gather more tweets this time to truly make a spaghetti chart):

To help de-clutter the vertex labels, we’ll only add labels for nodes that have a degree of 20 or more (rough guess — you should look at the degree distribution for more formal work). We’ll also include the degree for those nodes so we can size them properly:

Now, we’ll create the graph. Using ..index.. for the alpha channel will help show edge weight without too much extra effort. Note the heavy customization of geom_node_label(). Thomas made it way too easy to make beautiful network graphs with ggraph:

7.3 See Also

  • Enter twitter network analysis r into Google (seriously!). Lots of folks have worked in this space and blogged or wrote about their efforts.