Get startedGet started for free

Visualizing twitter networks

1. Visualizing twitter networks

Visualization of twitter networks helps understand complex networks in an easier and appealing way.

2. Lesson overview

In this lesson, we will plot and visualize a network with default parameters. Next, we will apply formatting attributes to the plot to improve readability. Finally, we will use centrality measures and network attributes to enhance the plot.

3. View a retweet network

To create a plot, let's view a retweet network created from tweets on hashtag OOTD.

4. Create the base network plot

We can create a base network plot by using the plot.igraph() function from the igraph library. This function takes the retweet network as input. The set.seed() function fixes the randomness to reproduce the same plot every time.

5. View the base network plot

The plot is created with vertices shown as orange circles and the edges indicated by grey lines. Let's now format the plot with attributes for better readability.

6. Format the plot

We add the following arguments to the plot() function. The aspect ratio is set to 9/16 to have a rectangular plot and the attributes vertex size and color, edge size and color, text label size and color are included.

7. View the formatted plot

In the plot, the number of arrows going out of a vertex is a measure of the number of times the user retweets. It will be more meaningful if the vertex size is proportional to the number of times the user retweets, or the out-degree.

8. Set vertex size based on the out-degree

Let's calculate the out-degree and assign it to a variable, deg_out. To avoid assigning zero values for the vertex size, we amplify this variable by multiplying deg_out by a random number 2 and adding 10 so the minimum vertex size is 10.

9. Assign vert_size to the vertex size attribute

We assign vert_size to the vertex size attribute and retain the other arguments in the plot.

10. View plot with new attributes

The vertex size is now proportionate to the out-degree. Vertices with bigger circles are the users who retweet more.

11. Adding network attributes

The users who retweet most will add more value if they have a high follower count as their retweets will reach a wider audience. We will modify the network plot to show users who retweet more and also have a high number of followers. To do this, we will add the follower count as a network attribute from an external data frame.

12. Follower count of network users

The data frame containing follower counts for the screen names in the network is imported using the readRDS() function.

13. View the followers data frame

The followers data frame has 2 columns: screen_name and followers_count.

14. Follower count of network users

In the followers data frame, we use the ifelse() function to create a new column which takes the value 1 when the follower count is greater than 500, else 0.

15. View the followers data frame

We now have a new column follow with values 1 or 0.

16. Assign network attributes

We assign the new column follow as an attribute called followers to the vertices of the network using the V() function. This function takes the retweet network as input.

17. View vertex attributes

We can view the network attributes with the vertex_attr() function. The network vertices have 2 attributes: name which is the screen name and followers with values 0 or 1.

18. Changing vertex colors

The vertex color can now be set based on the followers attribute. First, create a vector sub_color with values "lightgreen" and "tomato". In the plot attributes, input this sub_color for vertex.color. Here, map the vertex attribute followers as a factor to sub_color.

19. View plot formatted with vertex attributes

The vertices with followers equal to 1 i.e. with follower count above 500 are displayed in light green and the rest are displayed in the color tomato. The larger vertices colored light green are our most important users since they retweet the most and also have a high number of followers.

20. Let's practice!

We learned interesting ways to visualize twitter networks. Let's practice!