**I tried these codes in igraph v0.6, R 2.15, and all seems to be working fine. Let me know if you have any problems. (DS, Feb 9, 2013)
In this section, I'll run through methods to represent different qualities of nodes (vertices) in a network plot. I will mainly use igraph. For a full list of plotting arguments in igraph, use:
Our goal here will be to produce a network figure with different color and size for nodes, like this:
This requires loading vertex attributes in the network. In general, when you construct a network you will have some sort of data on the "attributes" of nodes. In our example, we'll use the sex of individuals as the main attribute that determines the color of the nodes. We'll then set the size of the nodes as the degree of the node (i.e., simply the number of edges that is connected to that node).
To do this, we'll first require a list of attributes that are associated with each node. I have supplied this at the bottom of this page as an attachment called "sample_attributes". As with other files, it is a .csv file. It looks like this:
Notice that I sorted this by sex so that the Bird.ID (i.e. vertex IDs) are not sorted in order. I did this on purpose since you often will not have the attributes file sorted exactly the way the IDs are arranged in the adjacency matrix.
The first thing to note is that in igraph, verted attributes have the notation
When you load a 'graph object' in igraph, the vertex names are automatically created, so:
what you want to do, then, is to assign attributes to these vertices. To assign the sex using your attributes file:
using this, you will then assign colors to the "F" and "M" categories, and move this to a vertex attribute named "color". This is a pre-assigned vertex attribute number. When you fill this, the plot will automatically refer to these values for setting node colors.
Now, let's play with the node size. Node size is set through a vertex attribute named "size". I'm going to set up the node size as the degree centrality of the nodes.
** The ALTERNATIVE way to do this is to set up a vector separately from the 'vertex attribute', and assign the color when you run the plot command. This works equally well.
for a full list of different vertex attributes you can assign this way, refer to look under ?plot.igraph or follow this link.
Some of the other useful attributes that have pre-assigned role inside the plot.igraph() function: