Want to learn more? Take the full course at [ Ссылка ] at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
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 "A-T-T-R - 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 set_vertex_attr() and set_edge_attr().
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_attr() and edge_attr() respectively.
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 inc(). 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 3.
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-dot-label-dot-color argument.
Now it's your turn.
#DataCamp #RTutorial #NetworkAnalysisinR
Ещё видео!