R Tutorial : Network Attributes

Learn how to attach and use vertex and edge attributes in igraph networks. Add properties like age or relationship type to your graph, subset edges by criteria like frequency ≥ 3, and color vertices based on attributes when you plot.
Chapters
Within any social network, we typically have more information about vertices and edges than whether they exist or not. This information may be important when we analyze or visualize the network. In the example network from the previous video, we already have one vertex attribute. Each vertex has a label or a name. We can see this in the igraph object where it says attr name. Vertex attributes may be categorical or numerical. In friendship or co worker networks, other vertex attributes may include the age, gender, or political affiliation of the individual. In a network of flight routes between cities, a vertex attribute may be the population of the city or the country that the vertex is in. Edges may also have attributes. This may refer to the type of relationship that individual vertices have. For instance, it could be whether an interconnection is romantic or Platonic in a friendship network, or whether a flight route between cities is scheduled daily or weekly. The most common edge attribute is the weight of the edge. The weight of an edge is visualized by adjusting the relative thickness of edges. The thicker the edge, the higher the weight of the edge. In a friendship network, the weight of an edge may refer to how many times in a week friends call each other. In a flight route network, it may refer to how many flights per week go between two cities. To add these attributes directly to networks that already exist as IGRAPH objects, you can use the functions SetVertexattribute and Set Edgeattribute. The first argument to each is the graph object. The second argument should be what you wish to call the new attribute. The final argument are the values to include. Here we are adding a vertex attribute called ages and an edge attribute called frequency. You can view vertex and edge attributes using the functions Vertex attribute and edgeattribute, respectively. Alternatively, if you already have all your attributes in dataframes, then you can create an igraph object that automatically contains all attributes by using graphfromdataframe. Often you may wish to inspect the igraph object to identify certain vertices or find edges that have some attribute. This is possible by subsetting the edges of the igraph object. In the first example, we are looking for all edges that include the vertex E using ink. The name of the vertex needs to be in quotes. In the second example, we subset all edges that have a frequency of greater than or equal to three. This can be very useful in large networks to identify interesting relationships. Finally, in this section you are going to further develop your igraph network visualization skills. It is possible to adjust basic igraph plots by adding parameters to the plot function. For instance, here we create a vertex attribute called color that igraph will use to plot vertex colors. We will make all vertices over the age of 22 red and make the remainder white. We also specify to add black labels to each vertex using the vertex label color argument. Now it's your turn.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







