Get startedGet started for free

Building a mentions graph

1. Building a mentions graph

We've already explored our retweet graph a bit, but the great thing about the fact that we're working with the raw data is that we can choose how to construct our graph. Depending the decisions we make, the same raw data can tell us different things. Previously we looked at how people retweeted about the rstats hashtag, but now let's build a slightly different graph, one that's centered around conversation, not retweets.

2. Recall tweet anatomy

Tweets that mention someone tend to be of two types: a reply to some earlier conversation, in which case the tweet starts off with a persons name or simply calling out someone when referencing their work as in the second tweet. If you'll recall all retweets started off with the capital letters RT. This means when we build up our graph, we have two challenges we didn't before. One: we can't simply pull out all the names, we need to specifically avoid names that are in retweets. Two: a given tweet might mention multiple people, so we need to pull out all the names, and in this case draw a link between AlexisAchim and four others.

3. Build your mentions graph

Just like when we built up our retweet graph, we first create an empty graph and then add a vertex for each screen name. Next we loop over all the raw tweets in our dataframe and extract all the screen names (recall that I have a special function for doing this that uses regular expressions, which is beyond the scope of this course). Because you can have multiple names in a tweet, the function returns a vector of names. Then just like before, if anything was returned we add the edges. However now we need an extra loop in case multiple screen names were returned. We make sure both vertices are in the graph, and add them if they're not, and finally add the edge. Lastly we simplify and trim out any vertices with no connection.

4. Comparing graphs - retweet graph

Here is our original plot of the retweet graph. It shows a dense central network of retweeters with some outlying pairs of vertices. Now let's look at our mention graph.

5. Comparing graphs - mention graph

The mention graph plot shows a substantially different graph. Here we can see there's a central graph where there are a number of connected conversations happening. However there are far more "side conversations" happening, lots of small subgraphs with just 2-3 people talking.

6. Let's practice!

Great! Now that we've created our mention graph and gotten quick visual sense of how it compares, let's use a more quantitative approach to see how these two graphs differ in things like degree distribution and reciprocity.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.