graphTweets not only allows to build graphs of interactions between users. It also lets you visualise what hashtag users use in their tweets and which hashtags are used together in the same tweets.

Users to Hashtags

The same principles follow, we simply use gt_edges_hash and pass the hashtags column as returned by rtweet. This creates a tibble of edges from screen_name to hashtags used in each tweet.

net <- tweets %>% 
  gt_edges(screen_name, hashtags) %>% 
  gt_nodes() %>% 
  gt_collect()

We’ll visualise the graph with sigmajs. Let’s prepare the data to meet the library’s requirements.

  • We add id to both nodes and edges
  • We add rename a few columns to meet sigmajs’ convention
  • We color the nodes by type (hashtag or user)

Apologies for not getting into details here but sigmajs is very well documented, check the website if you want to understand it all.

Let’s visualise it.

We use sg_layout to layout the graph and sg_neightbours to highlight nodes on click.

Hashtags Co-mentions

We can also build networks of hashtags co-mentions; when two or more hashtags are used in the same tweet they are connected on the graph.

Let’s look at the hashtags associated with #rstats

For this network use gt_edges_hashes and simply pass the hashtags column as it’s all that is needed.

Then again, we’ll use sigmajs for the visualisation. Since we got tweets on #rstats we will remove this node, it will be connected to all other hashtags. Make sure you remove it from both nodes and edges